This bugzilla service is closed. All entries have been migrated to

Bug 218

Summary: Compiler warning C4181: qualifier applied to reference type; ignored
Product: Eigen Reporter: mailhack
Component: GeneralAssignee: Nobody <eigen.nobody>
Severity: Compilation Problem CC: chtz, crobi, gael.guennebaud, hauke.heibel, jacob.benoit.1, jean.brefort
Priority: ---    
Version: 3.0   
Hardware: x86 - 32-bit   
OS: Windows   
Description Flags
compiler output with warnings
path that fixes the warning none

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):


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).

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:

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'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: