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++/57757] New: CPP extra inserted whitespace needs to be reviewed for C++11 user-defined literals


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57757

            Bug ID: 57757
           Summary: CPP extra inserted whitespace needs to be reviewed for
                    C++11 user-defined literals
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: harald at gigawatt dot nl

This invalid code

void operator"" _u(const char *, __SIZE_TYPE__) { }

#define ID(x) x
int main() {
  ID("")ID(_u);
}

is correctly rejected with

$ g++ -std=c++11 -c test.cc
test.cc: In function âint main()â:
test.cc:5:12: error: expected â;â before â_uâ
   ID("")ID(_u);
            ^
test.cc:3:15: note: in definition of macro âIDâ
 #define ID(x) x
               ^

as the "" and _u are separate tokens. However, with -save-temps, it gets
accepted incorrectly, because in the preprocessor output, "" and _u are joined
as ""_u.

$ g++ -std=c++11 -save-temps -c test.cc
(no output)

The preprocessor needs to insert a space between "" and _u in C++11 mode. For C
mode and C++03 mode, whitespace is not required, and as the documentation
states that GCC does not insert whitespace unless required, the preprocessor
output should only change in C++11 mode.

Modifying the example slightly, it's also possible to get something that
compiles without -save-temps, and gets rejected with it:

#define ID(x) x

void operator ID("")ID(_u)(const char *, __SIZE_TYPE__) { }

int main() {
  ""_u;
}

$ g++ -std=c++11 -c test.cc
$ g++ -std=c++11 -save-temps -c test.cc
test.cc:3:6: error: missing space between â""â and suffix identifier
 void operator ID("")ID(_u)(const char *, __SIZE_TYPE__) { }
      ^
test.cc: In function âint main()â:
test.cc:6:3: error: unable to find string literal operator âoperator"" _uâ
   ""_u;
   ^

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