Skip to content
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/unittests/HoverTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class Foo final {})cpp";
{{"int"}, std::string("T"), std::nullopt},
{{"bool"}, std::string("B"), std::nullopt},
};
HI.Value = "false";
return HI;
}},
// Lambda parameter with decltype
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3487,7 +3487,7 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
// C++23 [expr.const]p8 If we have a reference type allow unknown references
// and pointers.
bool AllowConstexprUnknown =
Info.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType();
Info.getLangOpts().CPlusPlus11 && VD->getType()->isReferenceType();

APValue::LValueBase Base(VD, Frame ? Frame->Index : 0, Version);

Expand Down
6 changes: 4 additions & 2 deletions clang/test/AST/ByteCode/builtin-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1398,9 +1398,11 @@ namespace BuiltinMemcpy {
// both-note {{destination of 'memcpy' is (void *)123}}


constexpr float type_pun(const unsigned &n) {
constexpr float type_pun(const unsigned &n) { // ref-error {{constexpr function never produces a constant expression}}
float f = 0.0f;
__builtin_memcpy(&f, &n, 4); // both-note {{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
// ref-note@+2 2{{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
// expected-note@+1 {{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
__builtin_memcpy(&f, &n, 4);
return f;
}
static_assert(type_pun(0x3f800000) == 1.0f); // both-error {{constant}} \
Expand Down
8 changes: 5 additions & 3 deletions clang/test/AST/ByteCode/cxx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace GlobalInitializer {
extern int &g; // both-note {{here}}
struct S {
int G : g; // both-error {{constant expression}} \
// both-note {{initializer of 'g' is unknown}}
// ref-note {{read of non-constexpr variable 'g' is not allowed in a constant expression}} expected-note {{initializer of 'g' is unknown}}
};
}

Expand Down Expand Up @@ -246,8 +246,10 @@ namespace IntToPtrCast {
}

namespace Volatile {
constexpr int f(volatile int &&r) {
return r; // both-note {{read of volatile-qualified type 'volatile int'}}
constexpr int f(volatile int &&r) { // ref-error {{constexpr function never produces a constant expression}}
// ref-note@+2 2{{read of volatile-qualified type 'volatile int'}}
// expected-note@+1 {{read of volatile-qualified type 'volatile int'}}
return r;
}
struct S {
int j : f(0); // both-error {{constant expression}} \
Expand Down
3 changes: 2 additions & 1 deletion clang/test/AST/ByteCode/openmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ int test1() {
int i;
int &j = i; // both-note {{declared here}}
float *f;
// both-note@+2 {{initializer of 'j' is not a constant expression}}
// ref-note@+3 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// both-error@+1 {{integral constant expression}}
#pragma omp for simd aligned(f:j)
for (int i = 0; i < 10; ++i);
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CXX/expr/expr.const/p2-0x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ namespace References {
int D2 : &d - &c + 1;
int E : e / 2;
int F : f - 11;
int G : g; // expected-error {{constant expression}} expected-note {{initializer of 'g' is unknown}}
int G : g; // expected-error {{constant expression}} expected-note {{read of non-constexpr variable 'g' is not allowed in a constant expression}}
int H : h(); // expected-error {{constant expression}} expected-note {{undefined function 'h'}}
int I : i; // expected-error {{constant expression}} expected-note {{initializer of 'i' is not a constant expression}}
int I : i; // expected-error {{constant expression}} expected-note {{read of non-constexpr variable 'i' is not allowed in a constant expression}}
int J : j();
int K : k;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class X { virtual ~X(); };
constexpr bool b = requires (X &x) { static_cast<int(*)[(typeid(x), 0)]>(nullptr); };
// expected-warning@-1 {{left operand of comma operator has no effect}}
// expected-warning@-2 {{variable length arrays in C++ are a Clang extension}}
// expected-note@-3{{function parameter 'x' with unknown value cannot be used in a constant expression}}
// expected-note@-4{{declared here}}
// expected-note@-3{{typeid applied to object 'x' whose dynamic type is not constant}}

namespace access_checks {
namespace in_requires_expression {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ template<class I, class C> int foomain(I argc, C **argv) {

#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
#pragma omp distribute parallel for simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}

for (I k = 0; k < argc; ++k) { ++k; v += j; }

Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/distribute_simd_aligned_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ template<class I, class C> int foomain(I argc, C **argv) {

#pragma omp target
#pragma omp teams
#pragma omp distribute simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
#pragma omp distribute simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}

for (I k = 0; k < argc; ++k) { ++k; v += j; }

Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/for_simd_aligned_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp for simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp for simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp masked taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp masked taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp master taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp master taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/parallel_for_simd_aligned_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp parallel for simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp parallel for simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp parallel masked taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp parallel masked taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp parallel master taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp parallel master taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/simd_aligned_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp target parallel for simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp target parallel for simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/target_simd_aligned_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp target simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp target simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ template<class I, class C> int foomain(I argc, C **argv) {

int v = 0;

#pragma omp target teams distribute parallel for simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
#pragma omp target teams distribute parallel for simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}

for (I k = 0; k < argc; ++k) { ++k; v += j; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ template<class I, class C> int foomain(I argc, C **argv) {

int v = 0;

#pragma omp target teams distribute simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
#pragma omp target teams distribute simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}

for (I k = 0; k < argc; ++k) { ++k; v += j; }

Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/taskloop_simd_aligned_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
// expected-note@+2 {{initializer of 'j' is not a constant expression}}
// expected-note@+2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error@+1 {{integral constant expression}}
#pragma omp taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
int v = 0;

#pragma omp target
#pragma omp teams distribute parallel for simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
#pragma omp teams distribute parallel for simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}

for (I k = 0; k < argc; ++k) { ++k; v += j; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
int v = 0;

#pragma omp target
#pragma omp teams distribute simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
#pragma omp teams distribute simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}

for (I k = 0; k < argc; ++k) { ++k; v += j; }

Expand Down
18 changes: 10 additions & 8 deletions clang/test/SemaCXX/constant-expression-cxx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,10 @@ constexpr int m2b = const_cast<const int&>(n2); // expected-error {{constant exp
struct T { int n; };
const T t = { 42 }; // expected-note {{declared here}}

constexpr int f(volatile int &&r) {
return r; // expected-note {{read of volatile-qualified type 'volatile int'}}
constexpr int f(volatile int &&r) { // cxx11_20-error {{constexpr function never produces a constant expression}}
// cxx11_20-note@+2 2{{read of volatile-qualified type 'volatile int'}}
// cxx23-note@+1 {{read of volatile-qualified type 'volatile int'}}
return r;
}
constexpr int g(volatile int &&r) {
return const_cast<int&>(r); // expected-note {{read of volatile temporary is not allowed in a constant expression}}
Expand Down Expand Up @@ -1475,9 +1477,9 @@ namespace ConvertedConstantExpr {
// useless note and instead just point to the non-constant subexpression.
enum class E {
em = m,
en = n, // expected-error {{enumerator value is not a constant expression}} cxx11_20-note {{initializer of 'n' is unknown}} cxx23-note {{read of non-constexpr variable 'n'}}
en = n, // expected-error {{enumerator value is not a constant expression}} expected-note {{read of non-constexpr variable 'n'}}
eo = (m + // expected-error {{not a constant expression}}
n // cxx11_20-note {{initializer of 'n' is unknown}} cxx23-note {{read of non-constexpr variable 'n'}}
n // expected-note {{read of non-constexpr variable 'n'}}
),
eq = reinterpret_cast<long>((int*)0) // expected-error {{not a constant expression}} expected-note {{reinterpret_cast}}
};
Expand Down Expand Up @@ -2435,15 +2437,15 @@ namespace array_size {
template<typename T> void f1(T t) {
constexpr int k = t.size();
}
template<typename T> void f2(const T &t) { // cxx11_20-note 2{{declared here}}
constexpr int k = t.size(); // cxx11_20-error 2{{constexpr variable 'k' must be initialized by a constant expression}} cxx11_20-note 2{{function parameter 't' with unknown value cannot be used in a constant expression}}
template<typename T> void f2(const T &t) {
constexpr int k = t.size();
}
template<typename T> void f3(const T &t) {
constexpr int k = T::size();
}
void g(array<3> a) {
f1(a);
f2(a); // cxx11_20-note {{in instantiation of function template}}
f2(a);
f3(a);
}

Expand All @@ -2452,7 +2454,7 @@ namespace array_size {
};
void h(array_nonstatic<3> a) {
f1(a);
f2(a); // cxx11_20-note {{instantiation of}}
f2(a);
}
//static_assert(f2(array_size::array<3>{}));
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaCXX/constexpr-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,9 @@ namespace MemcpyEtc {
static_assert(test_nontrivial_memmove()); // expected-error {{constant}} expected-note {{in call}}

// Type puns via constant evaluated memcpy are not supported yet.
constexpr float type_pun(const unsigned &n) {
constexpr float type_pun(const unsigned &n) { // expected-error {{constexpr function never produces a constant expression}}
float f = 0.0f;
__builtin_memcpy(&f, &n, 4); // expected-note {{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
__builtin_memcpy(&f, &n, 4); // expected-note 2{{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
return f;
}
static_assert(type_pun(0x3f800000) == 1.0f); // expected-error {{constant}} expected-note {{in call}}
Expand Down
Loading