-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Reland: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access #130673
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
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 |
---|---|---|
|
@@ -99,16 +99,29 @@ ShouldDiagnoseAvailabilityOfDecl(Sema &S, const NamedDecl *D, | |
// For typedefs, if the typedef declaration appears available look | ||
// to the underlying type to see if it is more restrictive. | ||
while (const auto *TD = dyn_cast<TypedefNameDecl>(D)) { | ||
if (Result == AR_Available) { | ||
if (const auto *TT = TD->getUnderlyingType()->getAs<TagType>()) { | ||
if (Result != AR_Available) | ||
break; | ||
for (const Type *T = TD->getUnderlyingType().getTypePtr(); /**/; /**/) { | ||
if (auto *TT = dyn_cast<TagType>(T)) { | ||
D = TT->getDecl(); | ||
Result = D->getAvailability(Message); | ||
} else if (isa<SubstTemplateTypeParmType>(T)) { | ||
// A Subst* node represents a use through a template. | ||
// Any uses of the underlying declaration happened through it's template | ||
// specialization. | ||
goto done; | ||
} else { | ||
const Type *NextT = | ||
T->getLocallyUnqualifiedSingleStepDesugaredType().getTypePtr(); | ||
if (NextT == T) | ||
goto done; | ||
T = NextT; | ||
continue; | ||
} | ||
Result = D->getAvailability(Message); | ||
break; | ||
} | ||
break; | ||
} | ||
|
||
done: | ||
Comment on lines
101
to
+124
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. This fixes #129681 (comment) |
||
// For alias templates, get the underlying declaration. | ||
if (const auto *ADecl = dyn_cast<TypeAliasTemplateDecl>(D)) { | ||
D = ADecl->getTemplatedDecl(); | ||
|
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
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 |
---|---|---|
|
@@ -14,4 +14,17 @@ bool try_acquire_for(T duration) { // expected-note{{'try_acquire_for<int>' has | |
int main() { | ||
try_acquire_for(1); // expected-warning{{'try_acquire_for<int>' is only available on macOS 11 or newer}} | ||
// expected-note@-1{{enclose 'try_acquire_for<int>' in a __builtin_available check to silence this warning}} | ||
} | ||
} | ||
|
||
namespace typename_template { | ||
struct [[clang::availability(macos, introduced = 16)]] A {}; | ||
|
||
template<class T> struct B { using type = T; }; | ||
template <class T> struct C { | ||
typename B<T>::type v; | ||
}; | ||
|
||
struct [[clang::availability(macos, introduced = 16)]] D { | ||
C<A> c; | ||
}; | ||
} // namespace typename_template | ||
Comment on lines
+19
to
+30
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. This tests #129681 (comment) |
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.
Do we need to take care of NTTP/template template parameters here?
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.
NTTP it looks unlikely, as we would be needing to dig through expressions, which we don't here, but maybe elsewhere.
Template Template parameters maybe, but it looks far fetched for the kind of application this availability thing has.