Consider simple code snippet
#include <map>
#include <string>
struct Foo
{
Foo(const std::map<std::string, int> & bar = std::map<std::string, int>())
:bar(bar)
{ }
std::map<std::string, int> bar;
};
int main(int argc, char ** argv)
{
return 0;
}
When I compile it like this: clang++ -o foo foo.cpp
I face errors:
foo.cpp:7:73: error: expected ')'
Foo(const std::map<std::string, int> bar = std::map<std::string, int>())
^
foo.cpp:7:8: note: to match this '('
Foo(const std::map<std::string, int> bar = std::map<std::string, int>())
^
foo.cpp:7:68: error: expected '>'
Foo(const std::map<std::string, int> bar = std::map<std::string, int>())
^
Same behaviour for clang 3.2 and clang 3.3.
So I am wondering if I missing something or is it a bug? GCC does not complain.
It's a fallacy in the C++ grammar that will surprise you. I'm unsure if this has been rectified or cleared out, see below.
All major compilers accept it though, including newer versions of Clang.
A list of references pertaining to the issue:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With