This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1549 - Passing anonymous enums as size parameters to .block() fails with g++ in C++03 mode
Summary: Passing anonymous enums as size parameters to .block() fails with g++ in C++0...
Status: RESOLVED WONTFIX
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.4 (development)
Hardware: All All
: Normal Compilation Problem
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-18 14:55 UTC by Christoph Hertzberg
Modified: 2019-12-04 17:40 UTC (History)
3 users (show)



Attachments

Description Christoph Hertzberg 2018-05-18 14:55:25 UTC
The following code fails on g++ when compiled in C++03 mode with the error:

error: no matching function for call to ‘Eigen::Matrix<double, -1, -1>::block(int, int, int, main()::<anonymous enum>)’


    Eigen::MatrixXd B;

    enum { rows = 4 };
    //const int rows = 4; // this works

    B.block(0,0, 5, rows);
    //B.block<Eigen::Dynamic, rows>(0,0, 5, rows); // this works


Using either of the commented variants instead works fine.
This was found by a former colleague when he upgraded his Eigen version.
This also works fine with current Eigen 3.3
Comment 1 Christoph Hertzberg 2018-05-18 14:58:57 UTC
Clang 'just' gives warnings:
warning: template argument uses local type '(anonymous enum at ../zz_test/block.cc:7:5)' [-Wlocal-type-template-args]

In c++11 (or higher) mode this compiles fine on either compiler (checked g++4.8,5.3 and clang++3.8,4.0,5.0).
Comment 2 Gael Guennebaud 2018-05-18 15:24:07 UTC
This is indeed a limitation of c++03 for which:

template<typename T> void foo(T) {}

void bar()
{
  enum { x };
  foo(x);
}


is not allowed. Your enum must both has a name AND not be local to a function:

enum x_type { x );
void bar()
{
  foo(x);
}

is fine in c++03, and if you do so, then your example works again. We could add a:

block(Index,Index,Index,Index)

overload but:

- we would need to do that for all variants of blocks (const/non const x *Corner, *Columns, *Rows, head, tail, etc.)  and add ugly SFINAE to the generic ones to enable them only if the non template one is not suitable .... which might be very tricky to get right. So: WONTFIX.
Comment 3 Christoph Hertzberg 2018-05-18 15:32:42 UTC
Ok, agreed. Especially, since the easy `const int`-workaround exists.
Comment 4 Nobody 2019-12-04 17:40:10 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1549.

Note You need to log in before you can comment on or make changes to this bug.