The following snippet compiles just fine using GCC 4.8.1 over at ideone.com,
but fails (on an admittedly old revision: ) of clang. What is the valid
syntax for this construct?
template <char... Chars>
class Obj;
template <char... Chars>
constexpr Obj<Chars...> operator "" _test();
template <char... Chars>
class Obj
{
friend Obj operator"" _test <Chars...>();
private:
constexpr Obj() { }
};
template <char... Chars>
constexpr Obj<Chars...> operator "" _test()
{
return Obj<Chars...>();
}
int main()
{
constexpr auto x = 1234_test;
return 0;
}
I'm compiling with *clang++ -std=c++11 literal.cpp*
The errors are (note the line numbers are funky because I commented out a
bunch of previous lines in the file to get this minimal reproduction):
literal.cpp:771:16: error: parameter declaration for literal operator
'operator "" _test' is not valid
friend Obj operator"" _test <Chars...>();
^
literal.cpp:780:12: error: calling a private constructor of class
'Obj<'1', '2', '3', '4'>'
return Obj<Chars...>();
^
literal.cpp:785:28: note: in instantiation of function template
specialization 'operator "" _test<'1', '2', '3', '4'>' requested here
constexpr auto x = 1234_test;
^
literal.cpp:774:15: note: declared private here
constexpr Obj() { }
^
literal.cpp:785:20: error: constexpr variable 'x' must be initialized by
a constant expression
constexpr auto x = 1234_test;
^ ~~~~~~~~~
3 errors generated.
_______________________________________________
cfe-users mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users