diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 74cae030bb9bb..cc2c092e9a8bf 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4872,7 +4872,7 @@ Compiler::visitVarDecl(const VarDecl *VD, const Expr *Init, // The previous attempt at initialization might've been unsuccessful, // so let's try this one. - return Init && checkDecl() && initGlobal(*GlobalIndex); + return !Init || (checkDecl() && initGlobal(*GlobalIndex)); } UnsignedOrNone GlobalIndex = P.createGlobal(VD, Init); diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index f47bc49d9a1a8..0b7d51be8d824 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -63,6 +63,19 @@ constexpr int test_address_of_incomplete_array_type() { // both-error {{never pr static_assert(test_address_of_incomplete_array_type() == 1234, ""); // both-error {{constant}} \ // both-note {{in call}} +namespace LocalExternRedecl { + constexpr int externRedecl1() { + extern int arr[]; + return 0; + } + constexpr int externRedecl2() { // both-error {{never produces a constant expression}} + extern int arr[]; + __builtin_memmove(&arr, &arr, 4 * sizeof(arr[0])); // both-note 2{{incomplete type}} + return 1234; + } + static_assert(externRedecl2() == 1234); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} struct NonTrivial { constexpr NonTrivial() : n(0) {}