[cfe-dev] C++11 error about initializing explicit constructor with {} ?

Csaba Raduly rcsaba at gmail.com
Fri Jan 18 01:49:07 PST 2013


Hi Benjamin,

On Thu, Jan 17, 2013 at 10:52 PM, Benjamin Redelings
<benjamin.redelings at duke.edu> wrote:
> Hi,
>
>     I'm trying to compile some of my C++11 code under clang-3.2; I
> originally wrote it under g++.  This is a case where g++-4.8 (snapshot)
> accepts my code, but clang-3.2 does not.  The error message is:
>
> In file included from ../../../master/src/mcmc/moves.C:20:
> In file included from ../../../master/src/mcmc/sample.H:26:
> ../../../master/src/mcmc/mcmc.H:390:94: error: chosen constructor is
> explicit in copy-initialization
>     std::set<int> get_affected_parameters(const
> owned_ptr<Probability_Model>&) const {return {};}
> ^~
> /usr/include/c++/v1/set:378:14: note: constructor declared here
>     explicit set(const value_compare& __comp = value_compare())
>
>
> So, basically, this code is trying to initialize a std::set<int> with {}.
> I'm not sure clang is right here, but I'm also not sure is wrong.  Can
> someone tell me, so I can possibly submit a bug report?

Maybe it's already fixed. The following code:

#include <set>
std::set<int> getset() { return {}; }

is compiled without errors by

$ clang++ -v --std=c++0x setinit.cc
clang version 3.3 (trunk 172707)
Target: x86_64-unknown-linux-gnu
Thread model: posix


Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds



More information about the cfe-dev mailing list