Bug 84517 - [8 Regression] "string literal"__FILE__ no longer accepted
Summary: [8 Regression] "string literal"__FILE__ no longer accepted
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2018-02-22 17:13 UTC by Jonathan Wakely
Modified: 2021-12-19 09:26 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2018-02-22 17:13:20 UTC
const char* err() { return "Error in "__FILE__; }

With GCC 7 this gave a warning:

file.cc:1:28: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 const char* err() { return "Error in "__FILE__; }
                            ^

But GCC 8 now rejects it:

file.cc: In function ‘const char* err()’:
file.cc:1:28: error: unable to find string literal operator ‘operator""__FILE__’ with ‘const char [10]’, ‘long unsigned int’ arguments
 const char* err() { return "Error in "__FILE__; }
                            ^~~~~~~~~~~~~~~~~~~

This was caused by r254443 for PR 80955

I'm not going to add the "rejects-valid" keyword, because technically the code is invalid, but we accept it as an extension because there is no matching UDL.
Comment 1 Jonathan Wakely 2018-02-27 14:42:42 UTC
Patch posted to https://gcc.gnu.org/ml/gcc-patches/2018-02/msg01503.html
Comment 2 Jonathan Wakely 2018-02-28 15:27:48 UTC
Author: redi
Date: Wed Feb 28 15:27:17 2018
New Revision: 258069

URL: https://gcc.gnu.org/viewcvs?rev=258069&root=gcc&view=rev
Log:
PR preprocessor/84517 allow double-underscore macros after string literals

gcc/testsuite:

	PR preprocessor/84517
	* g++.dg/cpp0x/udlit-macros.C: Expect a warning for ""__FILE__.

libcpp:

	PR preprocessor/84517
	* lex.c (is_macro_not_literal_suffix): New function.
	(lex_raw_string, lex_string): Use is_macro_not_literal_suffix to
	decide when to issue -Wliteral-suffix warnings.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/udlit-macros.C
    trunk/libcpp/ChangeLog
    trunk/libcpp/lex.c
Comment 3 Jonathan Wakely 2018-02-28 15:28:00 UTC
Fixed