From 9a17677bb8a332e873137187aba91f64d3fd16a0 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 26 Sep 2013 18:13:20 +0000 Subject: [PATCH] Per updates to D3781, allow underscore under ' in a pp-number, and allow ' in a #line directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191443 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/Lexer.cpp | 2 +- lib/Lex/PPDirectives.cpp | 5 +++++ test/Lexer/cxx1y_digit_separators.cpp | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index ee46895abd..3817afe75d 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1610,7 +1610,7 @@ bool Lexer::LexNumericConstant(Token &Result, const char *CurPtr) { if (C == '\'' && getLangOpts().CPlusPlus1y) { unsigned NextSize; char Next = getCharAndSizeNoWarn(CurPtr + Size, NextSize, getLangOpts()); - if (isAlphanumeric(Next)) { + if (isIdentifierBody(Next)) { if (!isLexingRawMode()) Diag(CurPtr, diag::warn_cxx11_compat_digit_separator); CurPtr = ConsumeChar(CurPtr, Size, Result); diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 7591992596..99b30c67ac 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -911,6 +911,11 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, // here. Val = 0; for (unsigned i = 0; i != ActualLength; ++i) { + // C++1y [lex.fcon]p1: + // Optional separating single quotes in a digit-sequence are ignored + if (DigitTokBegin[i] == '\'') + continue; + if (!isDigit(DigitTokBegin[i])) { PP.Diag(PP.AdvanceToTokenCharacter(DigitTok.getLocation(), i), diag::err_pp_line_digit_sequence) << IsGNULineDirective; diff --git a/test/Lexer/cxx1y_digit_separators.cpp b/test/Lexer/cxx1y_digit_separators.cpp index 2c83b1fcdb..59ad5d30f4 100644 --- a/test/Lexer/cxx1y_digit_separators.cpp +++ b/test/Lexer/cxx1y_digit_separators.cpp @@ -3,6 +3,8 @@ int operator""ms(unsigned long long); // expected-warning {{reserved}} float operator""ms(long double); // expected-warning {{reserved}} +int operator""_foo(unsigned long long); + namespace integral { static_assert(1'2'3 == 12'3, ""); static_assert(1'000'000 == 0xf'4240, ""); @@ -17,8 +19,7 @@ namespace integral { int f = 0b'1010; // expected-error {{invalid digit 'b' in octal}} int g = 123'ms; // expected-error {{digit separator cannot appear at end of digit sequence}} - // FIXME: not yet known if _ after ' will be permitted. - int z = 0'123'_foo; //'; // expected-error {{expected ';'}} + int z = 0'123'_foo; //'; // expected-error {{cannot appear at end of digit seq}} } namespace floating { @@ -32,3 +33,6 @@ namespace floating { float e = 1e'1; // expected-error {{digit separator cannot appear at start of digit sequence}} float f = 1e1'ms; // expected-error {{digit separator cannot appear at end of digit sequence}} } + +#line 123'456 +static_assert(__LINE__ == 123456, ""); -- 2.50.1