diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index d12bf9a9d1c..997cad83aea 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -9541,31 +9541,30 @@ public class AST2CPPTests extends AST2TestBase { assertEquals("A", ASTTypeUtil.getType(expr.getExpressionType())); } - // void f() { - // int i; - // int f1(); - // int&& f2(); - // int g(const int&); - // int g(const int&&); - // int j = g(i); // calls g(const int&) - // int k = g(f1()); // calls g(const int&&) - // int l = g(f2()); // calls g(const int&&) + // void test() { + // int i; + // int f1(); + // int&& f2(); + // int g(const int&); + // int g(const int&&); + // int j = g(i); // calls g(const int&) + // int k = g(f1()); // calls g(const int&&) + // int l = g(f2()); // calls g(const int&&) // } public void testRankingOfReferenceBindings() throws Exception { - String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); - IFunction g1= bh.assertNonProblem("g(const int&)", 1); - IFunction g2= bh.assertNonProblem("g(const int&&)", 1); + BindingAssertionHelper bh= getAssertionHelper(); + IFunction g1= bh.assertNonProblemOnFirstIdentifier("g(const int&)"); + IFunction g2= bh.assertNonProblemOnFirstIdentifier("g(const int&&)"); IFunction ref; - ref= bh.assertNonProblem("g(i);", 1); + ref= bh.assertNonProblemOnFirstIdentifier("g(i);"); assertSame(g1, ref); - ref= bh.assertNonProblem("g(f1());", 1); + ref= bh.assertNonProblemOnFirstIdentifier("g(f1());"); assertSame(g2, ref); - ref= bh.assertNonProblem("g(f2());", 1); + ref= bh.assertNonProblemOnFirstIdentifier("g(f2());"); assertSame(g2, ref); } - + // namespace std { // template class initializer_list; // } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index cfae877ad88..73d6885692d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -233,7 +233,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; /** - * Name resolution + * Name resolution. */ public class CPPSemantics { /** @@ -274,8 +274,9 @@ public class CPPSemantics { static protected IBinding resolveBinding(IASTName name) { if (traceBindingResolution) { - for (int i = 0; i < traceIndent; i++) + for (int i = 0; i < traceIndent; i++) { System.out.print(" "); //$NON-NLS-1$ + } System.out.println("Resolving " + name + ':' + ((ASTNode) name).getOffset()); //$NON-NLS-1$ traceIndent++; } @@ -311,8 +312,9 @@ public class CPPSemantics { binding = postResolution(binding, data); if (traceBindingResolution) { traceIndent--; - for (int i = 0; i < traceIndent; i++) + for (int i = 0; i < traceIndent; i++) { System.out.print(" "); //$NON-NLS-1$ + } System.out.println("Resolved " + name + ':' + ((ASTNode) name).getOffset() + //$NON-NLS-1$ " to " + DebugUtil.toStringWithClass(binding) + ':' + System.identityHashCode(binding)); //$NON-NLS-1$ } @@ -347,8 +349,9 @@ public class CPPSemantics { // 3.4.1-10 If we don't find a name used in a friend declaration in the member // declaration's class, we should look in the class granting friendship. IASTNode parent = lookupName.getParent(); - while (parent != null && !(parent instanceof ICPPASTCompositeTypeSpecifier)) + while (parent != null && !(parent instanceof ICPPASTCompositeTypeSpecifier)) { parent = parent.getParent(); + } if (parent instanceof ICPPASTCompositeTypeSpecifier) { IScope scope = ((ICPPASTCompositeTypeSpecifier) parent).getScope(); try { @@ -1528,8 +1531,9 @@ public class CPPSemantics { continue; } } - while (item instanceof IASTLabelStatement) + while (item instanceof IASTLabelStatement) { item= ((IASTLabelStatement) item).getNestedStatement(); + } if (item instanceof IASTDeclarationStatement) item = ((IASTDeclarationStatement) item).getDeclaration(); if (item instanceof ICPPASTUsingDirective) { @@ -1906,8 +1910,9 @@ public class CPPSemantics { // Point of declaration for a name is immediately after its complete declarator // and before its initializer. IASTDeclarator dtor = (IASTDeclarator)((nd instanceof IASTDeclarator) ? nd : nd.getParent()); - while (dtor.getParent() instanceof IASTDeclarator) + while (dtor.getParent() instanceof IASTDeclarator) { dtor = (IASTDeclarator) dtor.getParent(); + } IASTInitializer init = dtor.getInitializer(); // [basic.scope.pdecl]/p9: The point of declaration for a template parameter // is immediately after its complete template-parameter. @@ -2131,7 +2136,7 @@ public class CPPSemantics { return type; } - if (fns.size() > 0) { + if (!fns.isEmpty()) { final ICPPFunction[] fnArray = fns.keyArray(ICPPFunction.class); if (type != null && overrulesByRelevance(data, type, fnArray)) { return type; @@ -2878,8 +2883,9 @@ public class CPPSemantics { static IBinding resolveTargetedFunction(IASTName name, CPPFunctionSet functionSet) { boolean addressOf= false; IASTNode node= name.getParent(); - while (node instanceof IASTName) + while (node instanceof IASTName) { node= node.getParent(); + } if (!(node instanceof IASTIdExpression)) return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD); @@ -3362,8 +3368,9 @@ public class CPPSemantics { static enum LookupMode {NO_GLOBALS, GLOBALS_IF_NO_MEMBERS, LIMITED_GLOBALS, ALL_GLOBALS} static ICPPFunction findOverloadedOperator(IASTNode pointOfInstantiation, IScope pointOfDefinition, ICPPEvaluation[] args, IType methodLookupType, OverloadableOperator operator, LookupMode mode) { - while (pointOfInstantiation instanceof IASTName) + while (pointOfInstantiation instanceof IASTName) { pointOfInstantiation= pointOfInstantiation.getParent(); + } ICPPClassType callToObjectOfClassType= null; IType type2= null; @@ -3471,8 +3478,9 @@ public class CPPSemantics { } } if (j > 0) { - while (j < items.length) + while (j < items.length) { items[j++]= null; + } } } // 13.3.1.2.3 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index 4b99eb5d6d8..0e11a2f99d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -90,23 +90,23 @@ public class Conversions { public static Cost checkImplicitConversionSequence(IType target, IType exprType, ValueCategory valueCat, UDCMode udc, Context ctx, IASTNode point) throws DOMException { final boolean isImpliedObject= ctx == Context.IMPLICIT_OBJECT; - if (isImpliedObject) + if (isImpliedObject) udc= UDCMode.FORBIDDEN; - + target= getNestedType(target, TDEF); exprType= getNestedType(exprType, TDEF | REF); final IType cv1T1= getNestedType(target, TDEF | REF); final IType T1= getNestedType(cv1T1, TDEF | REF | ALLCVQ); - + if (target instanceof ICPPReferenceType) { ReferenceBinding refBindingType= ReferenceBinding.OTHER_REF; - // [8.5.3-5] initialization of a reference + // [8.5.3-5] initialization of a reference final boolean isLValueRef= !((ICPPReferenceType) target).isRValueReference(); final IType cv2T2= exprType; final IType T2= getNestedType(cv2T2, TDEF | REF | ALLCVQ); // mstodo: will change when implementing rvalue references on this pointer - final boolean isImplicitWithoutRefQualifier = isImpliedObject; + final boolean isImplicitWithoutRefQualifier = isImpliedObject; if (!isImplicitWithoutRefQualifier) { if (isLValueRef) { refBindingType= ReferenceBinding.LVALUE_REF; @@ -131,15 +131,15 @@ public class Conversions { // ... the initializer expression is an lvalue (but is not a bit field) // [for overload resolution bit-fields are treated the same, error if selected as best match] if (valueCat == LVALUE) { - // ... and "cv1 T1" is reference-compatible with "cv2 T2" + // ... and "cv1 T1" is reference-compatible with "cv2 T2" Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { cost.setReferenceBinding(refBindingType); return cost; - } + } } // ... or has a class type (i.e., T2 is a class type), where T1 is not reference-related to T2, and can be - // implicitly converted to an lvalue of type 'cv3 T3', where 'cv1 T1' is reference-compatible with + // implicitly converted to an lvalue of type 'cv3 T3', where 'cv1 T1' is reference-compatible with // 'cv3 T3' (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6) // and choosing the best one through overload resolution (13.3)), if (T2 instanceof ICPPClassType && udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2, point) < 0) { @@ -150,7 +150,7 @@ public class Conversions { } } } - + // Otherwise, the reference shall be an lvalue reference to a non-volatile const type (i.e., cv1 // shall be const), or the reference shall be an rvalue reference and the initializer expression // shall be an rvalue or have function type. @@ -186,21 +186,21 @@ public class Conversions { // otherwise, the program is ill-formed. return Cost.NO_CONVERSION; } - - // Otherwise, if T2 is a class type and + + // Otherwise, if T2 is a class type and if (T2 instanceof ICPPClassType) { // ... the initializer expression is an rvalue and 'cv1 T1' is reference-compatible with 'cv2 T2' // ..., then the reference is bound to the initializer expression rvalue in the first case if (valueCat.isRValue()) { Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { - // [13.3.3.1.4-1] direct binding has either identity or conversion rank. + // [13.3.3.1.4-1] direct binding has either identity or conversion rank. if (cost.getInheritanceDistance() > 0) { cost.setRank(Rank.CONVERSION); - } + } cost.setReferenceBinding(refBindingType); return cost; - } + } } // or T1 is not reference-related to T2 and the initializer expression can be implicitly @@ -217,7 +217,7 @@ public class Conversions { } } } - + // If the initializer expression is an rvalue, with T2 an array type, and 'cv1 T1' is // reference-compatible with 'cv2 T2' the reference is bound to the object represented by the // rvalue (see 3.10). @@ -233,7 +233,7 @@ public class Conversions { // expression using the rules for a non-reference copy initialization (8.5). The reference is then // bound to the temporary. If T1 is reference-related to T2, cv1 must be the same cv-qualification // as, or greater cv-qualification than, cv2; otherwise, the program is ill-formed. - + // 13.3.3.1.7 no temporary object when converting the implicit object parameter if (!isImpliedObject && ctx != Context.REQUIRE_DIRECT_BINDING) { if (isReferenceRelated(T1, T2, point) < 0 || compareQualifications(cv1T1, cv2T2) >= 0) { @@ -245,15 +245,15 @@ public class Conversions { } } return Cost.NO_CONVERSION; - } - + } + // Non-reference binding return nonReferenceConversion(valueCat, exprType, T1, udc, point); } /** - * C++0x: 13.3.1.6 Initialization by conversion function for direct reference binding - * @param point + * C++0x: 13.3.1.6 Initialization by conversion function for direct reference binding + * @param point */ private static Cost initializationByConversionForDirectReference(final IType cv1T1, final IType cv2T2, final ICPPClassType T2, boolean needLValue, Context ctx, IASTNode point) throws DOMException { @@ -263,7 +263,7 @@ public class Conversions { boolean ambiguousConversionOperator= false; if (fcns.length > 0 && !(fcns[0] instanceof IProblemBinding)) { for (final ICPPMethod op : fcns) { - // Note: the special case of initializing a temporary to be bound to the first parameter + // Note: the special case of initializing a temporary to be bound to the first parameter // of a copy constructor called with a single argument in the context of direct-initialization // is (more naturally) handled here rather than in copyInitializationOfClass(). if (op.isExplicit() && ctx != Context.FIRST_PARAM_OF_DIRECT_COPY_CTOR) @@ -324,10 +324,10 @@ public class Conversions { } if (udc == UDCMode.FORBIDDEN) return Cost.NO_CONVERSION; - + return copyInitializationOfClass(valueCat, source, (ICPPClassType) uqTarget, udc == UDCMode.DEFER, point); } - + if (uqSource instanceof ICPPClassType) { if (udc == UDCMode.FORBIDDEN) return Cost.NO_CONVERSION; @@ -346,7 +346,7 @@ public class Conversions { result.setListInitializationTarget(target); return result; } - + static Cost listInitializationSequenceHelper(EvalInitList arg, IType target, UDCMode udc, boolean isDirect, IASTNode point) throws DOMException { IType listType= getInitListType(target); if (listType == null && target instanceof IArrayType) { @@ -360,12 +360,12 @@ public class Conversions { } } } - + if (listType != null) { ICPPEvaluation[] clauses = arg.getClauses(); Cost worstCost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); for (ICPPEvaluation clause : clauses) { - Cost cost= checkImplicitConversionSequence(listType, clause.getTypeOrFunctionSet(point), + Cost cost= checkImplicitConversionSequence(listType, clause.getTypeOrFunctionSet(point), clause.getValueCategory(point), UDCMode.ALLOWED, Context.ORDINARY, point); if (!cost.converts()) return cost; @@ -379,12 +379,12 @@ public class Conversions { } return worstCost; } - + IType noCVTarget= getNestedType(target, CVTYPE | TDEF); if (noCVTarget instanceof ICPPClassType) { if (udc == UDCMode.FORBIDDEN) return Cost.NO_CONVERSION; - + ICPPClassType classTarget= (ICPPClassType) noCVTarget; if (TypeTraits.isAggregateClass(classTarget, point)) { Cost cost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); @@ -393,7 +393,7 @@ public class Conversions { } return listInitializationOfClass(arg, classTarget, isDirect, udc == UDCMode.DEFER, point); } - + ICPPEvaluation[] args = arg.getClauses(); if (args.length == 1) { final ICPPEvaluation firstArg = args[0]; @@ -407,7 +407,7 @@ public class Conversions { } else if (args.length == 0) { return new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); } - + return Cost.NO_CONVERSION; } @@ -437,7 +437,7 @@ public class Conversions { * ordering on cv-qualifiers, so that a type can be said to be more * cv-qualified than another. * @return