Dear all, I would like to post a fault report for the GNU C/C++ compiler 4.3.0. Used invokation line for the GNU C++ compiler: gcc -c -x c++ -ansi -Wall -Werror -mcpu=603e -fverbose-asm -mbig -mmultiple -mstring -mstrict-align -meabi -msdata -fno-common -fno-exceptions -fno-rtti -O3 -fno-section-anchors -I<different include paths> -D<different #define's> X.CPP -oX.O // example program struct X { X (void*); }; int i; volatile X ax1(&i); volatile X ax2 = &i; // <--- line 9 const volatile X bx1(&i); const volatile X bx2 = &i; // <--- line 12 GNU rejects the code fragment with the following error messages: X.CPP:9: error: no matching function for call to 'X::X(volatile X)' X.CPP:3: note: candidates are: X::X(void*) X.CPP:2: note: X::X(const X&) X.CPP:12: error: no matching function for call to 'X::X(const volatile X)' X.CPP:3: note: candidates are: X::X(void*) X.CPP:2: note: X::X(const X&) The initializations in lines 9 and 12 are copy-initializations with a call to the converting constructor "X::X (void*)". The result of this call is a temporary of type "X" (and not of type "[const] volatile X"), which can be copied with the implicitly-generated copy constructor "X::X (const X&)". BTW, the Comeau online compiler accepts the code above. Kind regards W. Roehrl
GCC 4.3 has been unsupported for some time. Go ahead and close this bug. If this issue can be reproduced with a supported version of GCC, please re-open it.
EDG also accepts this, 4.7.0 still fails to accept it. Confirmed.
Reproducible with const: $ cat main.cpp struct copyable { copyable() {} copyable(copyable&) {} }; struct wrapper { copyable c; wrapper(int) {} }; int main() { wrapper const w = 0; } $ g++-snapshot -Wall -Wextra -pedantic main.cpp main.cpp: In function 'int main()': main.cpp:15:23: error: no matching function for call to 'wrapper::wrapper(const wrapper)' main.cpp:15:23: note: candidates are: main.cpp:9:5: note: wrapper::wrapper(int) main.cpp:9:5: note: no known conversion for argument 1 from 'const wrapper' to 'int' main.cpp:6:8: note: wrapper::wrapper(wrapper&) main.cpp:6:8: note: no known conversion for argument 1 from 'const wrapper' to 'wrapper&' $ g++-snapshot -Wall -Wextra -pedantic -std=c++11 main.cpp main.cpp: In function 'int main()': main.cpp:15:23: error: no matching function for call to 'wrapper::wrapper(const wrapper)' main.cpp:15:23: note: candidates are: main.cpp:9:5: note: wrapper::wrapper(int) main.cpp:9:5: note: no known conversion for argument 1 from 'const wrapper' to 'int' main.cpp:6:8: note: wrapper::wrapper(wrapper&) main.cpp:6:8: note: no known conversion for argument 1 from 'const wrapper' to 'wrapper&' $ g++-snapshot -v ... gcc version 4.7.0 20120128 (experimental) [trunk revision 183664] (Debian 20120128-1) I noticed a similar problem when using copy-initialization on a const object of a class that is movable (with move constructor accepting T&&, not T const&&) but not copyable. I noticed that in C++11 8.5 Initializers [dcl.init] takes great care to specify: > [...] if the function is a constructor, the call initializes a temporary of the cv-unqualified version of the destination type. on paragraph 16 (I'm using n3290). I'm not as familiar with C++03 but apparently the text only mentions creation of a temporary, without exactly specifying of which type.
Let's ask Jason to double check the triage.
I agree with the analysis.
Fixed in GCC 4.9.1.
*** Bug 110685 has been marked as a duplicate of this bug. ***