This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 218 - Compiler warning C4181: qualifier applied to reference type; ignored
Summary: Compiler warning C4181: qualifier applied to reference type; ignored
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: General (show other bugs)
Version: 3.0
Hardware: x86 - 32-bit Windows
: --- Compilation Problem
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-07 10:21 UTC by mailhack
Modified: 2019-12-04 10:29 UTC (History)
6 users (show)



Attachments
compiler output with warnings (2.52 KB, text/plain)
2011-03-07 10:21 UTC, mailhack
no flags Details
path that fixes the warning (6.94 KB, patch)
2011-08-08 16:22 UTC, Robert Carnecky
no flags Details | Diff

Description mailhack 2011-03-07 10:21:23 UTC
Created attachment 129 [details]
compiler output with warnings

With Microsoft Visual Studio 2008 and Eigen 3.0-beta4, I get the the mentioned warning (see attached compiler output). My code is pretty unsuspicious and it compiled without warnings with Eigen 3.0-beta3.

This is the affected file (with line numbers):
utility.cpp


[...]

655:    Vector4f  V = es.eigenvectors().col(0).real();
656:    Quaternionf quat(V.x(), V.y(), V.z(), V.w());

[...]

815:    Vector3f dir(direction);
816:    dir.normalize();
817:    Vector3f z(0.f, 0.f, 1.f);
818:    Vector3f axis = z.cross(dir);
Comment 1 Benoit Jacob 2011-03-14 11:11:04 UTC
OK, the line of code in question at OrthoMethods.h:46 is:

  const typename internal::nested<Derived,2>::type lhs(derived());

This is a typedef so really this warning that you're getting is bogus. Actually it's already in our list of stupid warnings that we disable inside of Eigen, but we don't disable it outside of Eigen. If you want such known-stupid warnings to be permanently disabled, define EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS before including Eigen headers.
Comment 2 Robert Carnecky 2011-08-08 16:22:34 UTC
Created attachment 199 [details]
path that fixes the warning

The patch adds the const keyword to all versions of the internal::nested<T>::type definition and removes it from all places where internal::nested<T>::type is used.
Comment 3 Robert Carnecky 2011-08-08 16:50:59 UTC
As described in my post to the mailing list [1], I think this warning is legitimate. I have attached a patch that moves the const keyword to the type definition.

A few words on the patch: right now, internal::nested<T>::type always evaluates either to a reference to a const object or to a plain object, but never to a reference to a mutable object. internal::nested<T>::type is sometimes used with the const keyword, sometimes without. After the patch, the const is moved to the type definition, so that all local variables for evaluated nested expressions will be const.

Results of the tests with the patch applied: all 21 failtests passed, 560 tests passed, 16 tests did not build (error C2719: formal parameter with __declspec(align('16')) won't be aligned), and 1 test failed (qr_colpivoting3, random failure, cannot reproduce).

[1] http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2011/07/msg00042.html
Comment 4 Benoit Jacob 2011-08-09 07:48:02 UTC
First of all, this nested<> template will go away with bug 99. Marking as dependent.
Comment 5 Jean Brefort 2011-10-11 17:23:55 UTC
This warning is not stupid, it just says that the const keyword in this context is useless. You are actually using a reference to a non-const object. g++ does the same thing even if it doesn't complain.
Comment 6 Benoit Jacob 2011-10-11 17:41:09 UTC
Here the constness of the type in question depends on template parameters. In other cases the type may not be const-qualified already. Hence the const keyword here is not useless. Right?
Comment 7 Christoph Hertzberg 2014-06-15 01:05:29 UTC
It seems all those had been fixed meanwhile:
https://bitbucket.org/eigen/eigen/commits/479c46d

Re-open if any problem persists.
Comment 8 Nobody 2019-12-04 10:29:02 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/218.

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