This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80955] New: Macros expanded in definition of user-defined literals
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 02 Jun 2017 09:55:14 +0000
- Subject: [Bug c++/80955] New: Macros expanded in definition of user-defined literals
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80955
Bug ID: 80955
Summary: Macros expanded in definition of user-defined literals
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
This is valid, but fails to compile:
using size_t = decltype(sizeof(0));
#define _zero
int operator""_zero(const char*, size_t) { return 0; }
int main() { return ""_zero; }
The preprocessor should not expand the macro in ""_zero because it's a literal
suffix. They are not expanded at the point of use, but are incorrectly expanded
in the definition of the literal operator.
suf.cc:3:13: warning: invalid suffix on literal; C++11 requires a space between
literal and string macro [-Wliteral-suffix]
int operator""_zero(const char*, size_t) { return 0; }
^
suf.cc:4:21: warning: invalid suffix on literal; C++11 requires a space between
literal and string macro [-Wliteral-suffix]
int main() { return ""_zero; }
^
suf.cc:3:13: error: expected suffix identifier
int operator""_zero(const char*, size_t) { return 0; }
^~
suf.cc: In function ‘int main()’:
suf.cc:4:21: error: invalid conversion from ‘const char*’ to ‘int’
[-fpermissive]
int main() { return ""_zero; }
^~
N.B. It would be correct to expand the macro if it was defined like so:
int operator"" _zero(unsigned long long, size_t) { return 0; }