mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +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:
parent
0757b45da5
commit
2272a74f38
5 changed files with 27 additions and 7 deletions
|
@ -313,4 +313,21 @@ public class ReturnTypeDeductionTests extends AST2CPPTestBase {
|
||||||
BindingAssertionHelper helper = getAssertionHelper();
|
BindingAssertionHelper helper = getAssertionHelper();
|
||||||
helper.assertVariableType("waldo", CommonCPPTypes.int_);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -215,8 +215,6 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres
|
||||||
return EvalFixed.INCOMPLETE;
|
return EvalFixed.INCOMPLETE;
|
||||||
|
|
||||||
final ICPPEvaluation nestedEval = fOperand.getEvaluation();
|
final ICPPEvaluation nestedEval = fOperand.getEvaluation();
|
||||||
if (fOperator == op_bracketedPrimary)
|
|
||||||
return nestedEval;
|
|
||||||
|
|
||||||
if (nestedEval.isFunctionSet() && fOperator == op_amper) {
|
if (nestedEval.isFunctionSet() && fOperator == op_amper) {
|
||||||
return nestedEval;
|
return nestedEval;
|
||||||
|
|
|
@ -343,8 +343,9 @@ public class EvalMemberAccess extends CPPDependentEvaluation {
|
||||||
if (fMember instanceof ICPPField && !((ICPPField) fMember).isStatic()) {
|
if (fMember instanceof ICPPField && !((ICPPField) fMember).isStatic()) {
|
||||||
if (fIsPointerDeref)
|
if (fIsPointerDeref)
|
||||||
return LVALUE;
|
return LVALUE;
|
||||||
|
// Since C++11 (DR616), E1.E2 is an xvalue iff. E1 is not an lvalue and E2
|
||||||
return fOwnerValueCategory;
|
// has non reference type and designates a non-static data-member.
|
||||||
|
return fOwnerValueCategory == LVALUE ? LVALUE : XVALUE;
|
||||||
}
|
}
|
||||||
return LVALUE;
|
return LVALUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.IASTExpression.ValueCategory.PRVALUE;
|
||||||
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_alignOf;
|
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_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_minus;
|
||||||
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_noexcept;
|
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_noexcept;
|
||||||
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_not;
|
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_prefixDecr:
|
||||||
case op_prefixIncr:
|
case op_prefixIncr:
|
||||||
return LVALUE;
|
return LVALUE;
|
||||||
|
case op_bracketedPrimary:
|
||||||
|
// [expr.prim.paren]
|
||||||
|
return fArgument.getValueCategory();
|
||||||
default:
|
default:
|
||||||
return PRVALUE;
|
return PRVALUE;
|
||||||
}
|
}
|
||||||
|
@ -460,6 +464,8 @@ public class EvalUnary extends CPPDependentEvaluation {
|
||||||
return EvalPointer.createFromAddress(evalRef);
|
return EvalPointer.createFromAddress(evalRef);
|
||||||
}
|
}
|
||||||
return evalUnary;
|
return evalUnary;
|
||||||
|
} else if (fOperator == op_bracketedPrimary) {
|
||||||
|
return updateable != null ? updateable : fixed;
|
||||||
} else if (isModifyingOperation(fOperator)) {
|
} else if (isModifyingOperation(fOperator)) {
|
||||||
if (fixed instanceof EvalPointer) {
|
if (fixed instanceof EvalPointer) {
|
||||||
EvalPointer evalPointer = (EvalPointer) fixed;
|
EvalPointer evalPointer = (EvalPointer) fixed;
|
||||||
|
|
|
@ -810,9 +810,7 @@ public class SemanticHighlightingTest extends TestCase {
|
||||||
// };
|
// };
|
||||||
// int main() { //$functionDeclaration
|
// int main() { //$functionDeclaration
|
||||||
// Iter it; //$class,localVariableDeclaration
|
// Iter it; //$class,localVariableDeclaration
|
||||||
// // TODO: The fact that the opening parenthesis gets its own overloadedOperator
|
// 1 + (*it).waldo; //$overloadedOperator,localVariable,field
|
||||||
// // semantic highlighting is an (unrelated) bug.
|
|
||||||
// 1 + (*it).waldo; //$overloadedOperator,overloadedOperator,localVariable,field
|
|
||||||
// }
|
// }
|
||||||
public void testOverloadedOperatorStar_539535() throws Exception {
|
public void testOverloadedOperatorStar_539535() throws Exception {
|
||||||
makeAssertions();
|
makeAssertions();
|
||||||
|
|
Loading…
Add table
Reference in a new issue