[clang] [NFC][Clang] Fix enumerated mismatch warning (PR #112816)
Jinsong Ji via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 21 09:37:26 PDT 2024
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112816
>From 4d79a387c70f4460e7b82df171ba8db68c3a96aa Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 05:03:22 +0200
Subject: [PATCH 1/6] [NFC][Clang] Fix enumerated mismatch warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.
Fix warning:
llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3153:14: error: enumerated mismatch in conditional expression: ‘clang::diag::<unnamed enum>’ vs ‘clang::diag::<unnamed enum>’ [-Werror=enum-compare]
3152 | DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3153 | ? diag::err_friend_concept
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
3154 | : diag::
| ~~~~~~~~
3155 | err_concept_decls_may_only_appear_in_global_namespace_scope);
---
clang/include/clang/Basic/DiagnosticParseKinds.td | 3 ---
clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 78510e61a639fa..cb52629f9c61c7 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -983,9 +983,6 @@ def warn_cxx23_variadic_friends : Warning<
"variadic 'friend' declarations are incompatible with C++ standards before C++2c">,
DefaultIgnore, InGroup<CXXPre26Compat>;
-def err_friend_concept : Error<
- "friend declaration cannot be a concept">;
-
// C++11 default member initialization
def ext_nonstatic_member_init : ExtWarn<
"default member initializer for non-static data member is a C++11 "
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 883db838ca0147..d102a45f8c1ed2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3020,6 +3020,8 @@ def err_c23_constexpr_pointer_not_null : Error<
"constexpr pointer initializer is not null">;
// C++ Concepts
+def err_friend_concept : Error<
+ "friend declaration cannot be a concept">;
def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
"concept declarations may only appear in global or namespace scope">;
def err_concept_no_parameters : Error<
>From ea8950ea3cce2648adb5431efa55ae485403355b Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 14:58:27 +0200
Subject: [PATCH 2/6] cast instead
---
clang/include/clang/Basic/DiagnosticParseKinds.td | 3 +++
clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 --
clang/lib/Parse/ParseDeclCXX.cpp | 4 ++--
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index cb52629f9c61c7..78510e61a639fa 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -983,6 +983,9 @@ def warn_cxx23_variadic_friends : Warning<
"variadic 'friend' declarations are incompatible with C++ standards before C++2c">,
DefaultIgnore, InGroup<CXXPre26Compat>;
+def err_friend_concept : Error<
+ "friend declaration cannot be a concept">;
+
// C++11 default member initialization
def ext_nonstatic_member_init : ExtWarn<
"default member initializer for non-static data member is a C++11 "
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d102a45f8c1ed2..883db838ca0147 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3020,8 +3020,6 @@ def err_c23_constexpr_pointer_not_null : Error<
"constexpr pointer initializer is not null">;
// C++ Concepts
-def err_friend_concept : Error<
- "friend declaration cannot be a concept">;
def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
"concept declarations may only appear in global or namespace scope">;
def err_concept_no_parameters : Error<
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 6f0f5a0311bc18..fb159eb997ce9d 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3150,8 +3150,8 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
if (Tok.is(tok::kw_concept)) {
Diag(Tok.getLocation(),
DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
- ? diag::err_friend_concept
- : diag::
+ ? (unsigned)diag::err_friend_concept
+ : (unsigned)diag::
err_concept_decls_may_only_appear_in_global_namespace_scope);
SkipUntil(tok::semi, tok::r_brace, StopBeforeMatch);
return nullptr;
>From 12cd0928b31e075ee646c3e4a8d998f3e6277bdc Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 10:58:57 -0400
Subject: [PATCH 3/6] Update clang/lib/Parse/ParseDeclCXX.cpp
Co-authored-by: Sirraide <aeternalmail at gmail.com>
---
clang/lib/Parse/ParseDeclCXX.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index fb159eb997ce9d..fb27f6736c8a90 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3150,9 +3150,9 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
if (Tok.is(tok::kw_concept)) {
Diag(Tok.getLocation(),
DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
- ? (unsigned)diag::err_friend_concept
- : (unsigned)diag::
- err_concept_decls_may_only_appear_in_global_namespace_scope);
+ ? unsigned(diag::err_friend_concept)
+ : unsigned(diag::
+ err_concept_decls_may_only_appear_in_global_namespace_scope));
SkipUntil(tok::semi, tok::r_brace, StopBeforeMatch);
return nullptr;
}
>From 64c6ec24b9228994fcb28dc24029a96de5ee0655 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 17:00:31 +0200
Subject: [PATCH 4/6] clangformat
---
clang/lib/Parse/ParseDeclCXX.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index fb27f6736c8a90..c85486f05791b0 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3148,11 +3148,13 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
// we did nothing here, but this allows us to issue a more
// helpful diagnostic.
if (Tok.is(tok::kw_concept)) {
- Diag(Tok.getLocation(),
- DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
- ? unsigned(diag::err_friend_concept)
- : unsigned(diag::
- err_concept_decls_may_only_appear_in_global_namespace_scope));
+ Diag(
+ Tok.getLocation(),
+ DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
+ ? unsigned(diag::err_friend_concept)
+ : unsigned(
+ diag::
+ err_concept_decls_may_only_appear_in_global_namespace_scope));
SkipUntil(tok::semi, tok::r_brace, StopBeforeMatch);
return nullptr;
}
>From 9c4dd64ded34977d3fe57ad8f0ee45f4b1dc334f Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 19 Oct 2024 12:24:12 -0400
Subject: [PATCH 5/6] Update clang/lib/Parse/ParseDeclCXX.cpp
Co-authored-by: cor3ntin <corentinjabot at gmail.com>
---
clang/lib/Parse/ParseDeclCXX.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index c85486f05791b0..cb38de70aae9df 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3151,7 +3151,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
Diag(
Tok.getLocation(),
DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
- ? unsigned(diag::err_friend_concept)
+ ? llvm::to_underlying(diag::err_friend_concept)
: unsigned(
diag::
err_concept_decls_may_only_appear_in_global_namespace_scope));
>From 3554070edae0cc9e033c2158ed3e6ff73fe0de45 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 19 Oct 2024 12:24:20 -0400
Subject: [PATCH 6/6] Update clang/lib/Parse/ParseDeclCXX.cpp
Co-authored-by: cor3ntin <corentinjabot at gmail.com>
---
clang/lib/Parse/ParseDeclCXX.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index cb38de70aae9df..3b39bb895d5d83 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3152,7 +3152,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
Tok.getLocation(),
DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
? llvm::to_underlying(diag::err_friend_concept)
- : unsigned(
+ : llvm::to_underlying((
diag::
err_concept_decls_may_only_appear_in_global_namespace_scope));
SkipUntil(tok::semi, tok::r_brace, StopBeforeMatch);
More information about the cfe-commits
mailing list