Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang 3.1 and user defined literals

Clang 3.1 claims to support user defined literals. I can define this:

int operator"" _tryit(long double n) { return int(n); }

but when I try to use it I get an error:

int m = 5_tryit;

Invalid suffix '_tryit' on integer constant

like image 607
John Avatar asked Jun 04 '12 23:06

John


1 Answers

5 cannot be implicitly converted to a long double in your case. You need to change it to 5.0 to make it a long double or explicitly invoke the function yourself for the implicit conversion to work:

int m = 5.0_tryit;

OR

int n = operator"" _tryit(5);

(tested both with clang version 3.1 (trunk) (llvm/trunk 155821))

This SO question has a good explanation of the rules.

(Also, as abarnert mentions, make sure you are passing the -std=c++11 flag to the compiler when compiling).

like image 168
Jesse Good Avatar answered Sep 21 '22 16:09

Jesse Good