Skip to content

Commit cdae12c

Browse files
committed
[clang] add -fimplicit-constexpr flag: add one more test
1 parent 5f388d0 commit cdae12c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -verify=BEFORE,BOTH -std=c++23 %s
2+
// RUN: %clang_cc1 -verify=AFTER,BOTH -std=c++23 %s -fimplicit-constexpr
3+
4+
inline char read_byte(const char * ptr, int offset) {
5+
return *(ptr+offset);
6+
// AFTER-note@-1 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
7+
8+
}
9+
10+
inline char normal_function(int offset) {
11+
// BEFORE-note@-1 {{declared here}}
12+
char array[8] = {'a','b','c','d','e','f','g','h'};
13+
return read_byte(array, offset);
14+
// AFTER-note@-1 {{read_byte(&array[0], 8)}}
15+
}
16+
17+
constexpr char off_by_one_error = normal_function(8);
18+
// BOTH-error@-1 {{constexpr variable 'off_by_one_error' must be initialized by a constant expression}}
19+
// BEFORE-note@-2 {{non-constexpr function 'normal_function' cannot be used in a constant expression}}
20+
// AFTER-note@-3 {{in call to 'normal_function(8)'}}
21+
22+
23+

0 commit comments

Comments
 (0)