llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)

<details>
<summary>Changes</summary>

When dollars are supported in identifiers, we should be consistent.

Fixes #<!-- -->173985

---
Full diff: https://github.com/llvm/llvm-project/pull/208490.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+2-1) 
- (modified) clang/lib/Lex/Lexer.cpp (+2-2) 
- (added) clang/test/test/Lexer/dollar-idents.cpp (+17) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index be894701f5ce9..b0d80ebf34cac 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -787,6 +787,7 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 - Fixed an issue where `__typeof_unqual` and `__typeof_unqual__` were rejected 
as a declaration specifier in block scope in C++.
 - Fixed crash when checking for overflow for unary operator that can't 
overflow (#GH170072)
 - Clang no longer handles a `" q-char-sequence "` header name as a string 
literal (#GH132643).
+- Under `-fdollars-in-identifiers`, the `$` can now appear in 
user-defined-literals. (#GH173985)
 - Fixed an assertion where we improperly handled implicit conversions to 
integral types from an atomic-type with a conversion function. (#GH201770)
 - Fixed assertion failures involving code completion with delayed default 
arguments and exception specifications. (#GH200879)
 - Fixed a regression where calling a function that takes a class-type 
parameter by value inside `decltype` of a concept could be incorrectly rejected 
when used as a non-type template argument. (#GH175831)
@@ -1122,7 +1123,7 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 
 - Fixed a crash in code completion when using a C-Style cast with a 
parenthesized
   operand in Objective-C++ mode. (#GH180125)
-- Fixed a crash when code completion is triggered inside an ill-formed 
lambda's trailing requires-clause. (#GH201632)  
+- Fixed a crash when code completion is triggered inside an ill-formed 
lambda's trailing requires-clause. (#GH201632)
 
 ### Static Analyzer
 
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index f52b84a42ca70..4742fd2073f05 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2179,7 +2179,7 @@ const char *Lexer::LexUDSuffix(Token &Result, const char 
*CurPtr,
   char C = getCharAndSize(CurPtr, Size);
   bool Consumed = false;
 
-  if (!isAsciiIdentifierStart(C)) {
+  if (!isAsciiIdentifierStart(C, LangOpts.DollarIdents)) {
     if (C == '\\' && tryConsumeIdentifierUCN(CurPtr, Size, Result))
       Consumed = true;
     else if (!isASCII(C) && tryConsumeIdentifierUTF8Char(CurPtr, Result))
@@ -2217,7 +2217,7 @@ const char *Lexer::LexUDSuffix(Token &Result, const char 
*CurPtr,
       while (true) {
         auto [Next, NextSize] =
             getCharAndSizeNoWarn(CurPtr + Consumed, LangOpts);
-        if (!isAsciiIdentifierContinue(Next)) {
+        if (!isAsciiIdentifierContinue(Next, LangOpts.DollarIdents)) {
           // End of suffix. Check whether this is on the allowed list.
           const StringRef CompleteSuffix(Buffer, Chars);
           IsUDSuffix =
diff --git a/clang/test/test/Lexer/dollar-idents.cpp 
b/clang/test/test/Lexer/dollar-idents.cpp
new file mode 100644
index 0000000000000..d7b79f2964a92
--- /dev/null
+++ b/clang/test/test/Lexer/dollar-idents.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-user-defined-literals
+
+int $;  // no_dollar-error {{expected unqualified-id}}
+int $$; // no_dollar-error {{expected unqualified-id}}
+int Σ$; // no_dollar-error {{expected ';' after top level declarator}}
+int $Σ; // no_dollar-error {{expected unqualified-id}}
+
+using size_t = decltype(sizeof(void *));
+
+auto operator"" $(const char *p, size_t n) { return 0; } // no_dollar-error 
{{expected identifier}}
+auto operator"" $$(const char *p, size_t n) { return 0; } // no_dollar-error 
{{expected identifier}}
+auto operator"" Σ$(const char *p, size_t n) { return 0; } // no_dollar-error 
{{'operator""Σ' cannot be the name of a variable or data member}} \
+                                                          // no_dollar-error 
{{expected ';' after top level declarator}}
+auto operator"" $Σ(const char *p, size_t n) { return 0; } // no_dollar-error 
{{expected identifier}}
+auto operator"" Σ(const char *p, size_t n) { return 0; }
+
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/208490
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to