Skip to content

Commit 798c3e6

Browse files
committed
Add tests for new diagnostics
1 parent 24900d5 commit 798c3e6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,22 @@ constexpr bool may_overlap_different_encoding[] =
394394

395395
}
396396

397+
constexpr const char *getStr() {
398+
return "abc"; // expected-note {{repeated evaluation of the same literal expression can produce different objects}}
399+
}
400+
constexpr int strMinus() {
401+
(void)(getStr() - getStr()); // expected-note {{arithmetic on addresses of potentially overlapping literals has unspecified value}} \
402+
// cxx11-warning {{C++14 extension}}
403+
return 0;
404+
}
405+
static_assert(strMinus() == 0, ""); // expected-error {{not an integral constant expression}} \
406+
// expected-note {{in call to}}
407+
408+
constexpr int a = 0;
409+
constexpr int b = 1;
410+
constexpr int n = &b - &a; // expected-error {{must be initialized by a constant expression}} \
411+
// expected-note {{arithmetic involving unrelated objects '&b' and '&a' has unspecified value}}
412+
397413
namespace MaterializeTemporary {
398414

399415
constexpr int f(const int &r) { return r; }

0 commit comments

Comments
 (0)