[clang] 5ce5e98 - [Clang] Add warnings for CWG2521

2023-07-18 Thread Po-yao Chang via cfe-commits

Author: Po-yao Chang
Date: 2023-07-19T07:23:34+08:00
New Revision: 5ce5e983f82c802e44faa8ed42d605d70c045ba9

URL: 
https://github.com/llvm/llvm-project/commit/5ce5e983f82c802e44faa8ed42d605d70c045ba9
DIFF: 
https://github.com/llvm/llvm-project/commit/5ce5e983f82c802e44faa8ed42d605d70c045ba9.diff

LOG: [Clang] Add warnings for CWG2521

1. Teach -Wuser-defined-literals to warn on using double underscores in
   literal suffix identifiers.
2. Add -Wdeprecated-literal-operator to warn about the use of the first
   grammar production of literal-operator-id, which defaults to off for now.

Differential Revision: https://reviews.llvm.org/D152632

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/lib/Basic/IdentifierTable.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/drs/dr25xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cad10dd090263c..7d7c07f818e0fd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -142,6 +142,22 @@ Resolutions to C++ Defect Reports
 ^
 - Implemented `DR2397 `_ which allows ``auto`` 
specifier for pointers
   and reference to arrays.
+- Implemented `CWG2521 `_ which reserves using 
``__`` in user-defined
+  literal suffixes and deprecates literal operator function declarations using 
an identifier.
+  Taught ``-Wuser-defined-literals`` for the former, on by default, and added
+  ``-Wdeprecated-literal-operator`` for the latter, off by default for now.
+
+  .. code-block:: c++
+
+// What follows is warned by -Wuser-defined-literals
+// albeit "ill-formed, no diagnostic required".
+// Its behavior is undefined, [reserved.names.general]p2.
+string operator ""__i18n(const char*, std::size_t);
+
+// Assume this declaration is not in the global namespace.
+// -Wdeprecated-literal-operator diagnoses the extra space.
+string operator "" _i18n(const char*, std::size_t);
+//^ an extra space
 
 C Language Changes
 --

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index c0797166585e44..7b4d415bf06494 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -183,6 +183,7 @@ def DeprecatedCopyWithUserProvidedCopy : 
DiagGroup<"deprecated-copy-with-user-pr
 def DeprecatedCopyWithUserProvidedDtor : 
DiagGroup<"deprecated-copy-with-user-provided-dtor">;
 def DeprecatedCopy : DiagGroup<"deprecated-copy", 
[DeprecatedCopyWithUserProvidedCopy]>;
 def DeprecatedCopyWithDtor : DiagGroup<"deprecated-copy-with-dtor", 
[DeprecatedCopyWithUserProvidedDtor]>;
+def DeprecatedLiteralOperator : DiagGroup<"deprecated-literal-operator">;
 // For compatibility with GCC.
 def : DiagGroup<"deprecated-copy-dtor", [DeprecatedCopyWithDtor]>;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
@@ -220,6 +221,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedEnumFloatConversion,
   DeprecatedBuiltins,
   DeprecatedIncrementBool,
+  DeprecatedLiteralOperator,
   DeprecatedPragma,
   DeprecatedRegister,
   DeprecatedThisCapture,
@@ -865,7 +867,7 @@ def SignedEnumBitfield : DiagGroup<"signed-enum-bitfield">;
 
 def ReservedModuleIdentifier : DiagGroup<"reserved-module-identifier">;
 def ReservedIdentifier : DiagGroup<"reserved-identifier",
-[ReservedIdAsMacro, ReservedModuleIdentifier]>;
+[ReservedIdAsMacro, ReservedModuleIdentifier, UserDefinedLiterals]>;
 
 // Unreachable code warning groups.
 //

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d9932e0aa31a2a..52cca5acfd9245 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -406,6 +406,9 @@ def warn_reserved_extern_symbol: Warning<
   "it starts with '_' followed by a capital letter|"
   "it contains '__'}1">,
   InGroup, DefaultIgnore;
+def warn_deprecated_literal_operator_id: Warning<
+  "identifier %0 preceded by whitespace in a literal operator declaration "
+  "is deprecated">, InGroup, DefaultIgnore;
 def warn_reserved_module_name : Warning<
   "%0 is a reserved name for a module">, InGroup;
 
@@ -9261,8 +9264,8 @@ def ext_stri

[clang] bed75fa - [Clang] Reject programs declaring namespace std to be inline

2023-07-24 Thread Po-yao Chang via cfe-commits

Author: Po-yao Chang
Date: 2023-07-25T01:30:23+08:00
New Revision: bed75faf7d768f8375681db6a3fb7c3c35eeb5aa

URL: 
https://github.com/llvm/llvm-project/commit/bed75faf7d768f8375681db6a3fb7c3c35eeb5aa
DIFF: 
https://github.com/llvm/llvm-project/commit/bed75faf7d768f8375681db6a3fb7c3c35eeb5aa.diff

LOG: [Clang] Reject programs declaring namespace std to be inline

Fixes #64041

Differential Revision: https://reviews.llvm.org/D156063

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d5f179ae828f73..d6cf96bee488d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -84,6 +84,7 @@ C++ Language Changes
   directly rather than instantiating the definition from the standard library.
 - Implemented `CWG2518 `_ which allows 
``static_assert(false)``
   to not be ill-formed when its condition is evaluated in the context of a 
template definition.
+- Declaring namespace std to be an inline namespace is now prohibited, 
`[namespace.std]p7`.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fe4c3005c0ba3f..c88f25209fc0fa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1579,6 +1579,8 @@ def warn_inline_namespace_reopened_noninline : Warning<
   InGroup;
 def err_inline_namespace_mismatch : Error<
   "non-inline namespace cannot be reopened as inline">;
+def err_inline_namespace_std : Error<
+  "cannot declare the namespace 'std' to be inline">;
 
 def err_unexpected_friend : Error<
   "friends can only be classes or functions">;

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c59ab8b69594e5..b62f3c475c450c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11388,6 +11388,20 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
 
   NamespaceDecl *PrevNS = nullptr;
   if (II) {
+// C++ [namespace.std]p7:
+//   A translation unit shall not declare namespace std to be an inline
+//   namespace (9.8.2).
+//
+// Precondition: the std namespace is in the file scope and is declared to
+// be inline
+auto DiagnoseInlineStdNS = [&]() {
+  assert(IsInline && II->isStr("std") &&
+ CurContext->getRedeclContext()->isTranslationUnit() &&
+ "Precondition of DiagnoseInlineStdNS not met");
+  Diag(InlineLoc, diag::err_inline_namespace_std)
+  << SourceRange(InlineLoc, InlineLoc.getLocWithOffset(6));
+  IsInline = false;
+};
 // C++ [namespace.def]p2:
 //   The identifier in an original-namespace-definition shall not
 //   have been previously defined in the declarative region in
@@ -11408,7 +11422,10 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
 
 if (PrevNS) {
   // This is an extended namespace definition.
-  if (IsInline != PrevNS->isInline())
+  if (IsInline && II->isStr("std") &&
+  CurContext->getRedeclContext()->isTranslationUnit())
+DiagnoseInlineStdNS();
+  else if (IsInline != PrevNS->isInline())
 DiagnoseNamespaceInlineMismatch(*this, NamespaceLoc, Loc, II,
 &IsInline, PrevNS);
 } else if (PrevDecl) {
@@ -11420,6 +11437,8 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
   // Continue on to push Namespc as current DeclContext and return it.
 } else if (II->isStr("std") &&
CurContext->getRedeclContext()->isTranslationUnit()) {
+  if (IsInline)
+DiagnoseInlineStdNS();
   // This is the first "real" definition of the namespace "std", so update
   // our cache of the "std" namespace to point at this definition.
   PrevNS = getStdNamespace();

diff  --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp 
b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
index 39bed7db7ab38f..1e8df0cdd8ed79 100644
--- a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
 // FIXME: We should probably suppress the warning on reopening an inline
 // namespace without the inline keyword if it's not the first opening of the
@@ -16,3 +16,11 @@ namespace X {
   inline namespace {} // expected-note {{previous definition}}
   namespace {} // expected-warning {{inline namespace reopened as a non-inline 
namespace}}
 }
+
+namespace std {}
+inli

[clang] f2583f3 - [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-17 Thread Po-yao Chang via cfe-commits

Author: Po-yao Chang
Date: 2023-08-17T23:10:37+08:00
New Revision: f2583f3acf596cc545c8c0e3cb28e712f4ebf21b

URL: 
https://github.com/llvm/llvm-project/commit/f2583f3acf596cc545c8c0e3cb28e712f4ebf21b
DIFF: 
https://github.com/llvm/llvm-project/commit/f2583f3acf596cc545c8c0e3cb28e712f4ebf21b.diff

LOG: [Clang] CWG1473: do not err on the lack of space after operator""

In addition:
  1. Fix tests for CWG2521 deprecation warning.
  2. Enable -Wdeprecated-literal-operator by default.

Differential Revision: https://reviews.llvm.org/D153156

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr17xx.cpp
clang/test/CXX/drs/dr25xx.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p1.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p11.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p3.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p4.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p5.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p6.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p7.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p8.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p9.cpp
clang/test/CXX/over/over.oper/over.literal/p2.cpp
clang/test/CXX/over/over.oper/over.literal/p3.cpp
clang/test/CXX/over/over.oper/over.literal/p5.cpp
clang/test/CXX/over/over.oper/over.literal/p6.cpp
clang/test/CXX/over/over.oper/over.literal/p7.cpp
clang/test/CXX/over/over.oper/over.literal/p8.cpp
clang/test/CodeGenCXX/cxx11-user-defined-literal.cpp
clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
clang/test/FixIt/fixit-c++11.cpp
clang/test/OpenMP/amdgcn_ldbl_check.cpp
clang/test/PCH/cxx11-user-defined-literals.cpp
clang/test/Parser/cxx0x-literal-operators.cpp
clang/test/Parser/cxx11-user-defined-literals.cpp
clang/test/SemaCXX/cxx11-ast-print.cpp
clang/test/SemaCXX/cxx11-user-defined-literals-unused.cpp
clang/test/SemaCXX/cxx11-user-defined-literals.cpp
clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
clang/test/SemaCXX/cxx1z-user-defined-literals.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/test/SemaCXX/cxx98-compat.cpp
clang/test/SemaCXX/literal-operators.cpp
clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
clang/test/SemaCXX/reserved-identifier.cpp
clang/test/SemaCXX/warn-xor-as-pow.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1bfca926bf92a9..62c4ecdb32d8b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -92,6 +92,10 @@ C++2c Feature Support
 
 Resolutions to C++ Defect Reports
 ^
+- Implemented `CWG1473 `_ which allows spaces after 
``operator""``.
+  Clang used to err on the lack of space when the literal suffix identifier 
was invalid in
+  all the language modes, which contradicted the deprecation of the 
whitespaces.
+  Also turn on ``-Wdeprecated-literal-operator`` by default in all the 
language modes.
 
 C Language Changes
 --

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 940cca67368492..c5da98c4f0001e 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -276,12 +276,6 @@ def warn_cxx11_compat_reserved_user_defined_literal : 
Warning<
   "identifier after literal will be treated as a reserved user-defined literal 
"
   "suffix in C++11">,
   InGroup, DefaultIgnore;
-def ext_reserved_user_defined_literal : ExtWarn<
-  "invalid suffix on literal; C++11 requires a space between literal and "
-  "identifier">, InGroup, DefaultError;
-def ext_ms_reserved_user_defined_literal : ExtWarn<
-  "invalid suffix on literal; C++11 requires a space between literal and "
-  "identifier">, InGroup;
 def err_unsupported_string_concat : Error<
   "unsupported non-standard concatenation of string literals">;
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8c629aad89f48a..a30266d09dca7c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -411,7 +411,7 @@ def warn_reserved_extern_symbol: Warning<
   InGroup, DefaultIgnore;
 def warn_deprecated_literal_operator_id: Warning<
   "identifier %0 preceded by whitespace in a literal operator declaration "
-  "is deprecated">, InGroup, DefaultIgnore;
+  "is deprecated">, InGroup;
 def warn_reserved_module_name : Warning<
   "%0 is a reserved name for a module">, InGroup;
 

diff  --git a/clang/lib/Le

[clang] [clangd] Fix C++20 modules crash (PR #81919)

2024-02-15 Thread Po-yao Chang via cfe-commits

poyaoc97 wrote:

cc @ChuanqiXu9 

https://github.com/llvm/llvm-project/pull/81919
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits