From d4f884c550bec6b195eefb454636adc71449c041 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Mon, 7 Nov 2022 07:22:30 +0100 Subject: [PATCH] [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. --- clang/test/AST/Interp/cxx20.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp index 036e7f9..ec273f0 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}} -- 2.7.4