mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Bug 522066 - Use the declarator as the key for the recursion protection set in createAutoType()
Previously, the decl-specifier was used as the key, but a decl-specifier can be shared by multiple declarators, so seeing the same decl-specifier against doesn't necessarily mean we have infinite recursion. Change-Id: I165088c5379d412d1c31f2655c20a02629fbe596
This commit is contained in:
parent
398307d9bb
commit
9011fe1a95
2 changed files with 19 additions and 7 deletions
|
@ -12274,6 +12274,18 @@ public class AST2CPPTests extends AST2CPPTestBase {
|
|||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// struct Waldo {
|
||||
// int foo();
|
||||
// };
|
||||
//
|
||||
// int main() {
|
||||
// Waldo w;
|
||||
// auto i1 = w, i2 = i1.foo(); // Error on 'foo'
|
||||
// }
|
||||
public void testAutoWithTwoDeclarators_522066() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// constexpr int waldo = (sizeof(double) % 16);
|
||||
public void testSizeofDouble_506170() throws Exception {
|
||||
BindingAssertionHelper helper = getAssertionHelper();
|
||||
|
|
|
@ -253,13 +253,13 @@ public class CPPVisitor extends ASTQueries {
|
|||
// Common combinations of flags.
|
||||
public static final int DO_NOT_RESOLVE_PLACEHOLDERS = 0;
|
||||
|
||||
// Thread-local set of DeclSpecifiers for which auto types are being created.
|
||||
// Thread-local set of declarators for which auto types are being created.
|
||||
// Used to prevent infinite recursion while processing invalid self-referencing
|
||||
// auto-type declarations.
|
||||
private static final ThreadLocal<Set<IASTDeclSpecifier>> autoTypeDeclSpecs =
|
||||
new ThreadLocal<Set<IASTDeclSpecifier>>() {
|
||||
private static final ThreadLocal<Set<IASTDeclarator>> autoTypeDeclarators =
|
||||
new ThreadLocal<Set<IASTDeclarator>>() {
|
||||
@Override
|
||||
protected Set<IASTDeclSpecifier> initialValue() {
|
||||
protected Set<IASTDeclarator> initialValue() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
};
|
||||
|
@ -2166,8 +2166,8 @@ public class CPPVisitor extends ASTQueries {
|
|||
IType cannotDeduce = placeholderKind == PlaceholderKind.Auto ?
|
||||
ProblemType.CANNOT_DEDUCE_AUTO_TYPE :
|
||||
ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE;
|
||||
Set<IASTDeclSpecifier> recursionProtectionSet = autoTypeDeclSpecs.get();
|
||||
if (!recursionProtectionSet.add(declSpec)) {
|
||||
Set<IASTDeclarator> recursionProtectionSet = autoTypeDeclarators.get();
|
||||
if (!recursionProtectionSet.add(declarator)) {
|
||||
// Detected a self referring auto type, e.g.: auto x = x;
|
||||
return cannotDeduce;
|
||||
}
|
||||
|
@ -2272,7 +2272,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
recursionProtectionSet.remove(declSpec);
|
||||
recursionProtectionSet.remove(declarator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue