Skip to content

Commit 87dda6a

Browse files
authored
[Clang] Do not create a NoSFINAETrap for variable specialization. (llvm#191000)
There is no thing in the standard that says this should happen outside of the immediate context. Fixes llvm#54439
1 parent ebc5607 commit 87dda6a

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ Bug Fixes to C++ Support
427427
- Fixed a crash when a default argument is passed to an explicit object parameter. (#GH176639)
428428
- Fixed an alias template CTAD crash.
429429
- Fixed a crash when diagnosing an invalid static member function with an explicit object parameter (#GH177741)
430+
- Clang incorrectly instantiated variable specializations outside of the immediate context. (#GH54439)
430431
- Fixed a crash when instantiating an invalid out-of-line static data member definition in a local class. (#GH176152)
431432
- Fixed a crash when pack expansions are used as arguments for non-pack parameters of built-in templates. (#GH180307)
432433
- Fixed a bug where captured variables in non-mutable lambdas were incorrectly treated as mutable

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6013,7 +6013,6 @@ VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation(
60136013
if (FromVar->isInvalidDecl())
60146014
return nullptr;
60156015

6016-
NonSFINAEContext _(*this);
60176016
InstantiatingTemplate Inst(*this, PointOfInstantiation, FromVar);
60186017
if (Inst.isInvalid())
60196018
return nullptr;

clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_cc1 -std=c++98 -verify -fsyntax-only -Wno-unused-value -Wno-c++11-extensions -Wno-c++1y-extensions %s -DPRECXX11
22
// RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -Wno-unused-value -Wno-c++1y-extensions %s
33
// RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wno-unused-value %s
4+
// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wno-unused-value %s
45
// RUN: %clang_cc1 -std=c++2c -verify -fsyntax-only -Wno-unused-value %s
56

67

@@ -541,3 +542,28 @@ void test() {
541542
}
542543
}
543544
#endif
545+
546+
#if __cplusplus >= 202002L
547+
namespace GH54439 {
548+
template <bool B> struct enable_if {};
549+
template <> struct enable_if<true> {
550+
using type = void;
551+
};
552+
template <bool B> using enable_if_t = enable_if<B>::type;
553+
554+
template <typename T> inline constexpr bool dependent_false = false;
555+
556+
template <typename T>
557+
inline enable_if<dependent_false<T>>::type *is_foo = nullptr;
558+
559+
template <> inline constexpr bool is_foo<int> = true;
560+
561+
template <typename T>
562+
concept has_is_foo = requires { is_foo<T>; };
563+
564+
static_assert(has_is_foo<int>);
565+
566+
static_assert(not has_is_foo<float>);
567+
568+
}
569+
#endif

0 commit comments

Comments
 (0)