diff options
author | Felix Morgner | 2017-07-24 19:29:38 +0000 |
---|---|---|
committer | Nathan Ridge | 2019-02-22 08:29:05 +0000 |
commit | 2272a74f38283afd3a6777dae3d41e501c4c4c54 (patch) | |
tree | 0411fe9847c9c99f54c45157cd5a86a5e1ac7c7c /core | |
parent | 0757b45da5db47a65f59911c42eb9dcccfbdf972 (diff) | |
download | org.eclipse.cdt-2272a74f38283afd3a6777dae3d41e501c4c4c54.tar.gz org.eclipse.cdt-2272a74f38283afd3a6777dae3d41e501c4c4c54.tar.xz org.eclipse.cdt-2272a74f38283afd3a6777dae3d41e501c4c4c54.zip |
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>
Diffstat (limited to 'core')
5 files changed, 27 insertions, 7 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/ReturnTypeDeductionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/ReturnTypeDeductionTests.java index bcb161f0354..6c86c338777 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/ReturnTypeDeductionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/ReturnTypeDeductionTests.java @@ -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); + } }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java index 32ef93f67ce..d1d8e9ef8d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java index e32d8c97873..6ae8a86ccd8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java index 3d281195b7f..b90f0f92e61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java @@ -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; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java index 7537a80bb10..3d6e4ff4038 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java @@ -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(); |