This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/80955] New: Macros expanded in definition of user-defined literals


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; }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]