This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/41518] copy initialization of volatile objects


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41518

lucdanton at free dot fr changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lucdanton at free dot fr

--- Comment #3 from lucdanton at free dot fr 2012-02-15 15:08:11 UTC ---
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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]