1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 520117: [C++14] Return type deduction deduces wrong type for

parenthesized expressions in return

This patchset fixes 520117 and adjusts the value category of expressions
of kind E1.E2 to be standard (DR616) compliant.

Change-Id: I9a5cde805f2d0b39a2d263dbc3dcbefd3ba21930
Signed-off-by: Felix Morgner <fmorgner@hsr.ch>
This commit is contained in:
Felix Morgner 2017-07-24 21:29:38 +02:00 committed by Nathan Ridge
parent 0757b45da5
commit 2272a74f38
5 changed files with 27 additions and 7 deletions

View file

@ -313,4 +313,21 @@ public class ReturnTypeDeductionTests extends AST2CPPTestBase {
BindingAssertionHelper helper = getAssertionHelper();
helper.assertVariableType("waldo", CommonCPPTypes.int_);
}
// struct A {
// decltype(auto) f() { return (var); }
// int var{};
// };
public void testParenthesizedIdIsLValueReference_520117() throws Exception {
assertReturnType("f", CommonCPPTypes.referenceToInt);
}
// struct s{ int v{}; };
//
// decltype(auto) f() {
// return (s{}.v);
// }
public void testParenthesizedXValueIsRValueReference_520117() throws Exception {
assertReturnType("f", CommonCPPTypes.rvalueReferenceToInt);
}
}

View file

@ -215,8 +215,6 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres
return EvalFixed.INCOMPLETE;
final ICPPEvaluation nestedEval = fOperand.getEvaluation();
if (fOperator == op_bracketedPrimary)
return nestedEval;
if (nestedEval.isFunctionSet() && fOperator == op_amper) {
return nestedEval;

View file

@ -343,8 +343,9 @@ public class EvalMemberAccess extends CPPDependentEvaluation {
if (fMember instanceof ICPPField && !((ICPPField) fMember).isStatic()) {
if (fIsPointerDeref)
return LVALUE;
return fOwnerValueCategory;
// Since C++11 (DR616), E1.E2 is an xvalue iff. E1 is not an lvalue and E2
// has non reference type and designates a non-static data-member.
return fOwnerValueCategory == LVALUE ? LVALUE : XVALUE;
}
return LVALUE;
}

View file

@ -18,6 +18,7 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_alignOf;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_amper;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_bracketedPrimary;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_minus;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_noexcept;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_not;
@ -362,6 +363,9 @@ public class EvalUnary extends CPPDependentEvaluation {
case op_prefixDecr:
case op_prefixIncr:
return LVALUE;
case op_bracketedPrimary:
// [expr.prim.paren]
return fArgument.getValueCategory();
default:
return PRVALUE;
}
@ -460,6 +464,8 @@ public class EvalUnary extends CPPDependentEvaluation {
return EvalPointer.createFromAddress(evalRef);
}
return evalUnary;
} else if (fOperator == op_bracketedPrimary) {
return updateable != null ? updateable : fixed;
} else if (isModifyingOperation(fOperator)) {
if (fixed instanceof EvalPointer) {
EvalPointer evalPointer = (EvalPointer) fixed;

View file

@ -810,9 +810,7 @@ public class SemanticHighlightingTest extends TestCase {
// };
// int main() { //$functionDeclaration
// Iter it; //$class,localVariableDeclaration
// // TODO: The fact that the opening parenthesis gets its own overloadedOperator
// // semantic highlighting is an (unrelated) bug.
// 1 + (*it).waldo; //$overloadedOperator,overloadedOperator,localVariable,field
// 1 + (*it).waldo; //$overloadedOperator,localVariable,field
// }
public void testOverloadedOperatorStar_539535() throws Exception {
makeAssertions();