[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 19 05:13:23 PDT 2024
================
@@ -1306,3 +1306,18 @@ constexpr int field(int a) {
static_assert(field(3), ""); // expected-error {{constant expression}} \
// expected-note {{in call to 'field(3)'}}
}
+
+namespace literal_comparison {
+
+constexpr bool different_in_loop(bool b = false) {
+ if (b) return false;
+
+ const char *p[2] = {};
+ for (const char *&r : p)
+ r = "hello";
+ return p[0] == p[1]; // expected-note {{addresses of literals}}
+}
+constexpr bool check = different_in_loop();
+ // expected-error at -1 {{}} expected-note at -1 {{in call}}
+
+}
----------------
AaronBallman wrote:
Please add a newline to the end of the file.
https://github.com/llvm/llvm-project/pull/109208
More information about the cfe-commits
mailing list