[clang] Don't wrap immediate invocations in ConstantExprs within constexpr initializers (PR #89565)

Daniel M. Katz via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 07:20:40 PDT 2024


================
@@ -244,8 +244,8 @@ namespace UndefinedBehavior {
     constexpr int n13 = n5 + n5; // expected-error {{constant expression}} expected-note {{value -4294967296 is outside the range of }}
     constexpr int n14 = n3 - n5; // expected-error {{constant expression}} expected-note {{value 4294967295 is outside the range of }}
     constexpr int n15 = n5 * n5; // expected-error {{constant expression}} expected-note {{value 4611686018427387904 is outside the range of }}
-    constexpr signed char c1 = 100 * 2; // ok expected-warning{{changes value}}
-    constexpr signed char c2 = '\x64' * '\2'; // also ok  expected-warning{{changes value}}
+    constexpr signed char c1 = 100 * 2; // ok - no error from changing value because initializer is constexpr.
----------------
katzdm wrote:

Ah, just noticed - `enum-scoped.cpp` isn't a test that's affected by this change as-is. The suggested change adds an additional warning to where there's already an error; the declaration
```cpp
enum : signed char { A = 128 };
```

is diagnosed with:
```cpp
test2.cpp:1:26: warning: implicit conversion from 'int' to 'signed char' changes value from 128 to -128 [-Wconstant-conversion]
    1 | enum : signed char { A = 128 };
      |                          ^~~
test2.cpp:1:26: error: enumerator value evaluates to 128, which cannot be narrowed to type 'signed char' [-Wc++11-narrowing]
```

Not sure how helpful that additional diagnostic is.

https://github.com/llvm/llvm-project/pull/89565


More information about the cfe-commits mailing list