[clang] d4f884c - [clang][Interp] Add a test case for #58754

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 6 22:26:26 PST 2022


Author: Timm Bäder
Date: 2022-11-07T07:25:37+01:00
New Revision: d4f884c550bec6b195eefb454636adc71449c041

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

LOG: [clang][Interp] Add a test case for #58754

This works in the new interpreter but is rejected by the current one.
Make sure it keeps working.

Added: 
    

Modified: 
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 036e7f914bbed..ec273f0713410 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -86,3 +86,27 @@ constexpr int f() {
 }
 static_assert(f());
 #endif
+
+/// Distinct literals have disctinct addresses.
+/// see https://github.com/llvm/llvm-project/issues/58754
+constexpr auto foo(const char *p) { return p; }
+constexpr auto p1 = "test1";
+constexpr auto p2 = "test2";
+
+constexpr bool b1 = foo(p1) == foo(p1);
+static_assert(b1);
+
+constexpr bool b2 = foo(p1) == foo(p2); // ref-error {{must be initialized by a constant expression}} \
+                                        // ref-note {{declared here}}
+static_assert(!b2); // ref-error {{not an integral constant expression}} \
+                    // ref-note {{not a constant expression}}
+
+constexpr auto name1() { return "name1"; }
+constexpr auto name2() { return "name2"; }
+
+constexpr auto b3 = name1() == name1();
+static_assert(b3);
+constexpr auto b4 = name1() == name2(); // ref-error {{must be initialized by a constant expression}} \
+                                        // ref-note {{declared here}}
+static_assert(!b4); // ref-error {{not an integral constant expression}} \
+                    // ref-note {{not a constant expression}}


        


More information about the cfe-commits mailing list