Skip to content
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

[clang++] do not emit missing braces warning if all initializers are missing the same number of braces #111542

Open
t3nsor opened this issue Oct 8, 2024 · 0 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@t3nsor
Copy link

t3nsor commented Oct 8, 2024

Currently -Wmissing-braces is disabled in some useful cases (see here).

However the current rules still emit a warning in cases such as

struct A {
    int x;
};
struct B {
    int y;
};
struct S : A, B {
};
int main() {
    S s = {1, 2};
}

This pattern is used to implement an aggregate tuple template (templating has been omitted from this example for the sake of simplicity) which is useful in cases where tuples must be able to contain immovable types such as in senders & receivers based execution libraries.

I would like to suggest a generalization of the current rules that would avoid the warning in the example above: if all initializers provided are missing the same number of enclosing pairs of braces, then don't emit the warning. So in the std::array case there would be no warning because an outer pair of braces is missing, while in the above tuple case there would also be no warning because each initializer would be missing an inner pair of braces. Note that under this rule there would no longer be a warning for the AggregateAndEmpty case in aggregate-initialization.cpp but maybe there is a refinement of the rule that would preserve the warning in that case.

Currently, there is no way for library code to suppress the warning assuming that the user has turned on -Wmissing-braces. The warning suppression using #pragma must be done at the site of the aggregate initialization, not the class definition.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Oct 8, 2024
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang Clang issues not falling into any other category labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

2 participants