1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +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:
Nathan Ridge 2017-09-09 17:10:26 -04:00
parent 398307d9bb
commit 9011fe1a95
2 changed files with 19 additions and 7 deletions

View file

@ -12274,6 +12274,18 @@ public class AST2CPPTests extends AST2CPPTestBase {
parseAndCheckBindings(); 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); // constexpr int waldo = (sizeof(double) % 16);
public void testSizeofDouble_506170() throws Exception { public void testSizeofDouble_506170() throws Exception {
BindingAssertionHelper helper = getAssertionHelper(); BindingAssertionHelper helper = getAssertionHelper();

View file

@ -253,13 +253,13 @@ public class CPPVisitor extends ASTQueries {
// Common combinations of flags. // Common combinations of flags.
public static final int DO_NOT_RESOLVE_PLACEHOLDERS = 0; 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 // Used to prevent infinite recursion while processing invalid self-referencing
// auto-type declarations. // auto-type declarations.
private static final ThreadLocal<Set<IASTDeclSpecifier>> autoTypeDeclSpecs = private static final ThreadLocal<Set<IASTDeclarator>> autoTypeDeclarators =
new ThreadLocal<Set<IASTDeclSpecifier>>() { new ThreadLocal<Set<IASTDeclarator>>() {
@Override @Override
protected Set<IASTDeclSpecifier> initialValue() { protected Set<IASTDeclarator> initialValue() {
return new HashSet<>(); return new HashSet<>();
} }
}; };
@ -2166,8 +2166,8 @@ public class CPPVisitor extends ASTQueries {
IType cannotDeduce = placeholderKind == PlaceholderKind.Auto ? IType cannotDeduce = placeholderKind == PlaceholderKind.Auto ?
ProblemType.CANNOT_DEDUCE_AUTO_TYPE : ProblemType.CANNOT_DEDUCE_AUTO_TYPE :
ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE; ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE;
Set<IASTDeclSpecifier> recursionProtectionSet = autoTypeDeclSpecs.get(); Set<IASTDeclarator> recursionProtectionSet = autoTypeDeclarators.get();
if (!recursionProtectionSet.add(declSpec)) { if (!recursionProtectionSet.add(declarator)) {
// Detected a self referring auto type, e.g.: auto x = x; // Detected a self referring auto type, e.g.: auto x = x;
return cannotDeduce; return cannotDeduce;
} }
@ -2272,7 +2272,7 @@ public class CPPVisitor extends ASTQueries {
} }
} }
} finally { } finally {
recursionProtectionSet.remove(declSpec); recursionProtectionSet.remove(declarator);
} }
} }