Clang error: type A in generic association compatible with previously specified type B (err_assoc_compatible_types)
Jump to navigation
Jump to search
Text | error: type A in generic association compatible with previously specified type B |
---|---|
Type | Error |
Category | Semantic Issue |
Internal Id | err_assoc_compatible_types |
Internal Message | type %0 in generic association compatible with previously specified type %1
|
Regular Expression | (?:error|fatal error)\: type (.*?) in generic association compatible with previously specified type (.*?)
|
First Commit | 2011-04-15 91147596414d C1X: implement generic selections |
Description
Example
Flags | -xc -std=c11 -pedantic-errors
|
|
---|---|---|
Source |
int f(int x) {
_Generic(x, int: x, default: x, int: x); // Duplicate type 'int'
return 0;
}
| |
Compiler Output |
<source>:2:35: error: type 'int' in generic association compatible with previously specified type 'int' <source>:2:15: note: compatible type 'int' specified here <source>:4:2: error: no newline at end of file [-Werror,-Wnewline-eof] |
Clang Internals (17.0.6)
Git Commit Message
C1X: implement generic selections As an extension, generic selection support has been added for all supported languages. The syntax is the same as for C1X. llvm-svn: 129554
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaExpr.cpp (line 1777)
ExprResult Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef<TypeSourceInfo *> Types, ArrayRef<Expr *> Exprs) {
// ...
for (unsigned i = 0; i < NumAssocs; ++i) {
// ...
if (Types[i]) {
// ...
if (Types[i]->getType()->isDependentType()) {
// ...
} else {
// ...
// C11 6.5.1.1p2 "No two generic associations in the same generic
// selection shall specify compatible types."
for (unsigned j = i + 1; j < NumAssocs; ++j)
if (Types[j] && !Types[j]->getType()->isDependentType() && Context.typesAreCompatible(Types[i]->getType(), Types[j]->getType())) {
Diag(Types[j]->getTypeLoc().getBeginLoc(), diag::err_assoc_compatible_types) << Types[j]->getTypeLoc().getSourceRange() << Types[j]->getType() << Types[i]->getType();
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/Sema/attr-btf_type_tag.c
- clang/test/Sema/attr-btf_type_tag.c:32:19: error: type 'int *' in generic association compatible with previously specified type 'int __attribute__((btf_type_tag("tag1")))*' (aka 'int *')