[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-25 Thread Shafik Yaghmour via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


shafik wrote:

Thank you for doing this work.

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-16 Thread Shoaib Meenai via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


smeenai wrote:

https://github.com/boostorg/mpl/issues/69 is still a problem, unfortunately.

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-14 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-14 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From 08b5c95bea5b7bfceeae6dfc4deac764faff87a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/2] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 4 
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1eebf5ea6b3e382..ade3c33b3b9444c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,10 @@ C++ Specific Potentially Breaking Changes
   Clang as a compiler, but it may break assumptions in Clang-based tools
   iterating over the AST.
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on
+  system headers and macros. It will be turned into a hard (non-downgradable)
+  error in the next Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 83d8ad39ee5544ad9bab848901362de0b180b2b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/2] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-13 Thread Aaron Ballman via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


https://github.com/AaronBallman approved this pull request.

LGTM!

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-13 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?G=C3=A1lvez?= ,
Carlos =?utf-8?q?G=C3=A1lvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

Friendly ping @AaronBallman @shafik 

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread David Blaikie via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


dwblaikie wrote:

> It seems checks are broken on trunk, I see commits merged with failing 
> pre-merge tests. They seem to be unrelated to this patch though.
> 
> Is there anything else you'd like fixed before merging? @dwblaikie 
> @AaronBallman @shafik

Nothing further from me, at least. But maybe wait for approval from one of the 
other two.

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

It seems checks are broken on trunk, I see commits merged with failing 
pre-merge tests. They seem to be unrelated to this patch though.

Is there anything else you'd like fixed before merging? @dwblaikie 
@AaronBallman @shafik 

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From 7a70366e08f2c2f1181bb74f7716d8b1e3f1b62e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/3] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8f5a67e14c9aba3..6a1afa656a470b4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 45fe235f06c4c1693e555baab2bedf233bef57e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/3] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

I would need some help with the failing pre-merge test, I don't really 
understand why that failure would be related to this patch...

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/3] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 8dc78e7dda5d1db625eb45a8d32409fe1c91ea87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/3] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 



@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,

carlosgalvezp wrote:

Done. 

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/2] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 8dc78e7dda5d1db625eb45a8d32409fe1c91ea87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/2] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux 

[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits


@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,

carlosgalvezp wrote:

Yes, will fix!

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Mariya Podchishchaeva via cfe-commits


@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,

Fznamznon wrote:

Do we need a test for this change?

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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

…macros

As per review comments on https://reviews.llvm.org/D150226, we should allow for 
one more release before turning this warning into a hard error, by making it 
visible in system headers and macros, so that people are aware of it and can 
work on it.

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


2 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticASTKinds.td (+2-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

``




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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-09-27 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/67528

…macros

As per review comments on https://reviews.llvm.org/D150226, we should allow for 
one more release before turning this warning into a hard error, by making it 
visible in system headers and macros, so that people are aware of it and can 
work on it.

>From f9c4fb4e0a5a9017da6214fb0d98f45f89ee16be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..3b6cfa776c85e46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits