- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
When compiling example below, you will get warning:
#469: temporary used for initial value of reference to non-const (anachronism)
and when another overload is added (see comment) warning disappears, but compiler still choose "BOOL" overload instead of "OBJECT". Note that disabling microsoft extensions (/Za) brings warning back.
We are using x64 compiler for visual studio 2013, version 15.0.1.148 build 20141023 on windows 7.
#include <iostream> struct T {}; struct P { P(T*) {} }; void f(bool&) { std::cout << "BOOL" << std::endl; } //uncomment this function to hide compilation warning //void f(P) { std::cout << "OBJECT" << std::endl; } int main() { f(new T); return 0; }
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have, another question. Is it possible to disable initialization of non const references from temporary object with microsoft extensions enabled and overloaded function? We want to drop /Za option and make compiler behave like /Qdiag-error:469 is enabled end warning remains.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regarding the first question -- we actually emit a slightly different diagnostic for when the overload is declared which can only be seen with the /W5 option or if it is explicitly requested, i.e.:
74% icl -c /Qdiag-warning:504 bug.cpp
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Ve
rsion 15.0 Beta Build x
Built Mar 11 2015 14:01:59 by jward4 on JWARD4-DESK1 in D:/workspaces/15_0cfe/de
v
Copyright (C) 1985-2015 Intel Corporation. All rights reserved.
bug.cpp
bug.cpp(13): warning #504: initial value of reference to non-const must be an lvalue
f(new T);
^
75%
We try to be warning for warning compatible with Microsoft and in the case of the overload Microsoft does not emit any diagnostic so we do not either.
For the second question -- if you use /Qdiag-error:504 and /Qdiag-error:469 then both examples with get an error even without the /Za option.
Judy

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page