-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang] Instantiate variables referenced in decltype
with an undeduced type.
#161231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4c01522
[Clang] Instantiate variables referenced in `decltype` with an undedu…
cor3ntin 83d1532
fix tests
cor3ntin dcd9853
add tests
cor3ntin 8e56a50
add test for GH56652
cor3ntin 401f939
add test for GH1163191
cor3ntin ffdbc5e
more tests
cor3ntin 73316aa
more tests
cor3ntin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-elf-gnu %s -emit-llvm -o - | FileCheck %s | ||
|
||
namespace GH56652{ | ||
|
||
struct foo {}; | ||
|
||
template <typename T> struct bar { | ||
using type = T; | ||
|
||
template <foo> inline static constexpr auto b = true; | ||
}; | ||
|
||
template <typename T> | ||
concept C = requires(T a) { T::template b<foo{}>; }; | ||
|
||
template <typename T> auto fn(T) { | ||
if constexpr (!C<T>) | ||
return foo{}; | ||
else | ||
return T{}; | ||
} | ||
|
||
auto a = decltype(fn(bar<int>{})){}; | ||
|
||
} | ||
|
||
namespace GH116319 { | ||
|
||
template <int = 0> struct a { | ||
template <class> static constexpr auto b = 2; | ||
template <class> static void c() noexcept(noexcept(b<int>)) {} | ||
}; | ||
|
||
void test() { a<>::c<int>(); } | ||
|
||
|
||
} | ||
|
||
// CHECK: %"struct.GH56652::bar" = type { i8 } | ||
// CHECK: $_ZN8GH1163191aILi0EE1cIiEEvv = comdat any | ||
// CHECK: @_ZN7GH566521aE = global %"struct.GH56652::bar" undef |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wno-c99-designator %s | ||
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wno-c99-designator %s | ||
|
||
// PR5290 | ||
int const f0(); | ||
|
@@ -156,13 +157,90 @@ struct A { | |
} | ||
}; | ||
|
||
|
||
|
||
// This shouldn't crash. | ||
static_assert(A<int>().f<int>() == 0, ""); | ||
// The result should not be dependent. | ||
static_assert(A<int>().f<int>() != 0, ""); // expected-error {{static assertion failed due to requirement 'GH99873::A<int>().f<int>() != 0'}} | ||
// expected-note@-1 {{expression evaluates to '0 != 0'}} | ||
} | ||
|
||
|
||
#if __cplusplus >= 201703L | ||
namespace GH160497 { | ||
|
||
template <class> struct S { | ||
template <class> | ||
inline static auto mem = | ||
[] { static_assert(false); // expected-error {{static assertion failed}} \ | ||
// expected-note {{while substituting into a lambda expression here}} | ||
return 42; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test ONLY tests |
||
}(); | ||
}; | ||
|
||
using T = decltype(S<void>::mem<void>); | ||
// expected-note@-1 {{in instantiation of static data member 'GH160497::S<void>::mem<void>' requested here}} | ||
|
||
|
||
template <class> struct S2 { | ||
template <class> | ||
inline static auto* mem = | ||
[] { static_assert(false); // expected-error {{static assertion failed}} \ | ||
// expected-note {{while substituting into a lambda expression here}} | ||
return static_cast<int*>(nullptr); | ||
}(); | ||
}; | ||
|
||
using T2 = decltype(S2<void>::mem<void>); | ||
//expected-note@-1 {{in instantiation of static data member 'GH160497::S2<void>::mem<void>' requested here}} | ||
|
||
template <class> struct S3 { | ||
template <class> | ||
inline static int mem = // Check we don't instantiate when the type is not deduced. | ||
[] { static_assert(false); | ||
return 42; | ||
}(); | ||
}; | ||
|
||
using T = decltype(S3<void>::mem<void>); | ||
} | ||
|
||
namespace N1 { | ||
|
||
template<class> | ||
struct S { | ||
template<class> | ||
inline static auto mem = 42; | ||
}; | ||
|
||
using T = decltype(S<void>::mem<void>); | ||
|
||
T y = 42; | ||
|
||
} | ||
|
||
namespace GH161196 { | ||
|
||
template <typename> struct A { | ||
static constexpr int digits = 0; | ||
}; | ||
|
||
template <typename> struct B { | ||
template <int, typename MaskInt = int, int = A<MaskInt>::digits> | ||
static constexpr auto XBitMask = 0; | ||
}; | ||
|
||
struct C { | ||
using ReferenceHost = B<int>; | ||
template <int> static decltype(ReferenceHost::XBitMask<0>) XBitMask; | ||
}; | ||
|
||
void test() { (void)C::XBitMask<0>; } | ||
|
||
} | ||
#endif | ||
|
||
template<typename> | ||
class conditional { | ||
}; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wonder if this should be
isUndeducedAutoType
. This ends up doing a type visitor to check if there is ANY 'auto' in the type (GetContainedDeducedTypeVisitor
).Do we expect this to work with an
auto*
return type to the lambda, etc? I actually lean towards YES, but would love a test or two?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we condition this check on
TSK != TSK_Undeclared
? As it stands, every time any variable is mentioned we'll walk its type looking forauto
, which sounds quite expensive, given how common name references to variables are.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, note that we do have the same check inside this function
So it would be at least worth combining it into a bool variable.
@cor3ntin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw that, I'll make a PR