-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang] Check std::initializer_list more strictly
#133822
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
Open
offsetof
wants to merge
3
commits into
llvm:main
Choose a base branch
from
offsetof:std-initializer-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,77 @@ | ||
| // RUN: %clang_cc1 %s -verify=expected,type-param -std=c++23 -DTYPE_PARAM | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DCONSTANT_PARAM | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DTYPE_TEMPLATE_PARAM | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DDEFAULT_ARG | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DMULTIPLE_PARAMS | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DPARAM_PACK | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DCONSTRAINED_PARAM | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DREQUIRES_CLAUSE | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DNONCLASS_TEMPLATE | ||
| // RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DNONTEMPLATE | ||
|
|
||
|
Comment on lines
+1
to
+11
Contributor
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. Why isn't that a single test?
Contributor
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. Because otherwise they're redefined |
||
| namespace std { | ||
|
|
||
| #ifdef TYPE_PARAM | ||
| template<class> class initializer_list; | ||
| // expected-note@-1 2 {{template is declared here}} | ||
| #elifdef CONSTANT_PARAM | ||
| template<int> class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list must have a type template parameter}} | ||
| #elifdef TYPE_TEMPLATE_PARAM | ||
| template<template<class> class> class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list must have a type template parameter}} | ||
| #elifdef DEFAULT_ARG | ||
| template<class = int> class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list cannot have default template arguments}} | ||
| #elifdef MULTIPLE_PARAMS | ||
| template<class, class> class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list must have exactly one template parameter}} | ||
| #elifdef PARAM_PACK | ||
| template<class...> class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list cannot be a variadic template}} | ||
| #elifdef CONSTRAINED_PARAM | ||
| template<class> concept C = true; | ||
| template<C> class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list cannot have associated constraints}} | ||
| #elifdef REQUIRES_CLAUSE | ||
| template<class> requires true class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list cannot have associated constraints}} | ||
| #elifdef NONCLASS_TEMPLATE | ||
| template<class> class IL; | ||
| template<class T> using initializer_list = IL<T>; | ||
| // expected-error@-1 2 {{std::initializer_list must be a class template}} | ||
| #elifdef NONTEMPLATE | ||
| class initializer_list; | ||
| // expected-error@-1 2 {{std::initializer_list must be a class template}} | ||
| #else | ||
| #error Unexpected test kind | ||
| #endif | ||
|
|
||
| } | ||
|
|
||
| struct Test { // expected-note 2 {{candidate constructor}} | ||
| #ifdef CONSTANT_PARAM | ||
| Test(std::initializer_list<1>); // expected-note {{candidate constructor}} | ||
| #elifdef TYPE_TEMPLATE_PARAM | ||
| template<class> using A = double; | ||
| Test(std::initializer_list<A>); // expected-note {{candidate constructor}} | ||
| #elifdef MULTIPLE_PARAMS | ||
| Test(std::initializer_list<double, double>); // expected-note {{candidate constructor}} | ||
| #elifdef NONTEMPLATE | ||
| Test(std::initializer_list); // expected-note {{candidate constructor}} | ||
| #else | ||
| Test(std::initializer_list<double>); // expected-note {{candidate constructor}} | ||
| #endif | ||
| }; | ||
| Test test {1.2, 3.4}; // expected-error {{no matching constructor}} | ||
|
|
||
| auto x = {1}; | ||
| // type-param-error@-1 {{implicit instantiation of undefined template}} | ||
| // others-note@-2 {{used here}} | ||
|
|
||
| void f() { | ||
| for(int x : {1, 2}); | ||
| // type-param-error@-1 {{implicit instantiation of undefined template}} | ||
| // type-param-error@-2 {{invalid range expression}} | ||
| // others-note@-3 {{used here}} | ||
| } | ||
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.
Couldn't we use CheckStdInitializerList?
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.
It currently takes a
ClassTemplateDecl, but hereFoundis some other kind of declaration