SmallVector<unsigned, 1> CompatIndices;
unsigned DefaultIndex = -1U;
+ // Look at the canonical type of the controlling expression in case it was a
+ // deduced type like __auto_type. However, when issuing diagnostics, use the
+ // type the user wrote in source rather than the canonical one.
for (unsigned i = 0; i < NumAssocs; ++i) {
if (!Types[i])
DefaultIndex = i;
- else if (Context.typesAreCompatible(ControllingExpr->getType(),
+ else if (Context.typesAreCompatible(
+ ControllingExpr->getType().getCanonicalType(),
Types[i]->getType()))
CompatIndices.push_back(i);
}
__typeof__(i) : 0, // expected-note {{compatible type 'typeof (i)' (aka 'int') specified here}}
__typeof__(a) : 1); // expected-error {{type 'typeof (a)' (aka 'int') in generic association compatible with previously specified type 'typeof (i)' (aka 'int')}}
}
+
+void Issue55702(void) {
+ // A controlling expression which uses __auto_type should not be
+ // automatically compatible with every association; we should be using the
+ // canonical type for that comparison.
+ void *ptr = 0;
+ __auto_type v = ptr;
+ (void)_Generic(v, long double : 0, double : 0, default : 1); // OK
+ _Static_assert(_Generic(v, long double : 0, default : 1) == 1, "fail");
+}