summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-12-18 03:09:36 (EST)
committer Sergey Prigogin2013-12-18 14:29:16 (EST)
commite0d1910ed4dba5202c810cc5993bf751ac9e15d3 (patch)
treeee805e9e1bcad99f569a40203b30ea8e7762f2ab
parent227b03e6b8d46f61d4a0d8df9a0526b5d6c99ee1 (diff)
downloadorg.eclipse.cdt-e0d1910ed4dba5202c810cc5993bf751ac9e15d3.zip
org.eclipse.cdt-e0d1910ed4dba5202c810cc5993bf751ac9e15d3.tar.gz
org.eclipse.cdt-e0d1910ed4dba5202c810cc5993bf751ac9e15d3.tar.bz2
Bug 420995 - Specializations of constexpr functionsrefs/changes/36/19936/2
Change-Id: I7e08e21eb62867d6bb42aa6904ab0fab472cb0bc Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/19936 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java17
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorInstance.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorSpecialization.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java18
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java2
13 files changed, 79 insertions, 22 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
index 1961359..de894db 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
@@ -8251,4 +8251,21 @@ public class AST2TemplateTests extends AST2TestBase {
public void testStrayFriends_419301() throws Exception {
parseAndCheckBindings();
}
+
+ // template <typename T>
+ // constexpr T t(T) {
+ // return 0;
+ // }
+ //
+ // template <>
+ // constexpr unsigned t<unsigned>(unsigned) {
+ // return 1 + 1;
+ // }
+ //
+ // constexpr unsigned waldo = t(0u);
+ public void testSpecializationOfConstexprFunction_420995() throws Exception {
+ BindingAssertionHelper helper = getAssertionHelper();
+ ICPPVariable waldo = helper.assertNonProblem("waldo");
+ assertEquals(2, waldo.getInitialValue().numericalValue().longValue());
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
index 1209dfc..b1624fb 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
@@ -2454,4 +2454,19 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
public void testFriendFunctionOfClassSpecialization_419301b() throws Exception {
checkBindings();
}
+
+ // template <typename T>
+ // constexpr T t(T) {
+ // return 0;
+ // }
+ //
+ // template <>
+ // constexpr unsigned t<unsigned>(unsigned) {
+ // return 1 + 1;
+ // }
+
+ // // empty source file
+ public void testSpecializationOfConstexprFunction_420995() throws Exception {
+ checkBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
index ba209e6..b84c4bd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
@@ -422,7 +422,7 @@ public class Value implements IValue {
if (expr instanceof ICPPASTInitializerClause) {
ICPPEvaluation evaluation = ((ICPPASTInitializerClause) expr).getEvaluation();
- return new Value(null, evaluation);
+ return evaluation.getValue(expr);
}
return UNKNOWN;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java
index 866ecda..88217c5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java
@@ -35,8 +35,14 @@ public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument {
evaluation.isTypeDependent() || evaluation.isValueDependent()) {
fEvaluation= evaluation;
} else {
- fEvaluation= new EvalFixed(evaluation.getTypeOrFunctionSet(point),
- evaluation.getValueCategory(point), evaluation.getValue(point));
+ IValue value = evaluation.getValue(point);
+ // Avoid nesting EvalFixed's as nesting causes the signature to be different.
+ if (value.getEvaluation() instanceof EvalFixed) {
+ fEvaluation = value.getEvaluation();
+ } else {
+ fEvaluation= new EvalFixed(evaluation.getTypeOrFunctionSet(point),
+ evaluation.getValueCategory(point), value);
+ }
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java
index 59b4730..5a791eb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java
@@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
-import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromReturnType;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromReturnType;
@@ -149,12 +148,10 @@ public class EvalFunctionCall extends CPPDependentEvaluation {
@Override
public IValue getValue(IASTNode point) {
ICPPEvaluation eval = computeForFunctionCall(Value.MAX_RECURSION_DEPTH, point);
- if (eval != this) {
- if (eval instanceof EvalFixed)
- return ((EvalFixed) eval).getValue();
- eval = new EvalFixed(getTypeOrFunctionSet(point), PRVALUE, eval.getValue(point));
- }
- return Value.create(eval);
+ if (eval == this) {
+ return Value.create(eval);
+ }
+ return eval.getValue(point);
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorInstance.java
index 7af275a..988a9f6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorInstance.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorInstance.java
@@ -28,7 +28,7 @@ public class PDOMCPPConstructorInstance extends PDOMCPPMethodInstance implements
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPMethodInstance.RECORD_SIZE + 0;
- public PDOMCPPConstructorInstance(PDOMLinkage linkage, PDOMNode parent, ICPPMethod method,
+ public PDOMCPPConstructorInstance(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method,
PDOMBinding instantiated) throws CoreException {
super(linkage, parent, method, instantiated);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorSpecialization.java
index d3e5e21..3769739 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPConstructorSpecialization.java
@@ -27,7 +27,7 @@ class PDOMCPPConstructorSpecialization extends PDOMCPPMethodSpecialization imple
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPMethodSpecialization.RECORD_SIZE + 0;
- public PDOMCPPConstructorSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPConstructor constructor, PDOMBinding specialized) throws CoreException {
+ public PDOMCPPConstructorSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPConstructor constructor, PDOMBinding specialized) throws CoreException {
super(linkage, parent, constructor, specialized);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java
index 7cea574..358d6cc 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java
@@ -38,7 +38,7 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunctionSpecialization.RECORD_SIZE + 8;
- public PDOMCPPFunctionInstance(PDOMLinkage linkage, PDOMNode parent, ICPPFunction function, PDOMBinding orig)
+ public PDOMCPPFunctionInstance(PDOMCPPLinkage linkage, PDOMNode parent, ICPPFunction function, PDOMBinding orig)
throws CoreException {
super(linkage, parent, function, orig);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java
index 8698367..1f50d3a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java
@@ -23,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPComputableFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
@@ -84,7 +83,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
private short fAnnotation= -1;
private int fRequiredArgCount= -1;
- public PDOMCPPFunctionSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPFunction astFunction,
+ public PDOMCPPFunctionSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPFunction astFunction,
PDOMBinding specialized) throws CoreException {
super(linkage, parent, (ICPPSpecialization) astFunction, specialized);
@@ -123,10 +122,6 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
fAnnotation = getAnnotation(astFunction);
db.putShort(record + ANNOTATION, fAnnotation);
db.putShort(record + REQUIRED_ARG_COUNT , (short) astFunction.getRequiredArgumentCount());
- ICPPEvaluation returnExpression = CPPFunction.getReturnExpression(astFunction);
- if (returnExpression != null) {
- linkage.storeEvaluation(record + RETURN_EXPRESSION, returnExpression);
- }
long typelist= 0;
if (astFunction instanceof ICPPMethod && ((ICPPMethod) astFunction).isImplicit()) {
// Don't store the exception specification, it is computed on demand.
@@ -134,6 +129,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
typelist = PDOMCPPTypeList.putTypes(this, astFunction.getExceptionSpecification());
}
db.putRecPtr(record + EXCEPTION_SPEC, typelist);
+ linkage.new ConfigureFunctionSpecialization(astFunction, this);
}
private short getAnnotation(ICPPFunction astFunction) {
@@ -154,6 +150,16 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
super(linkage, bindingRecord);
}
+ public void initData(ICPPEvaluation returnExpression) {
+ if (returnExpression == null)
+ return;
+ try {
+ getLinkage().storeEvaluation(record + RETURN_EXPRESSION, returnExpression);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ }
+
@Override
protected int getRecordSize() {
return RECORD_SIZE;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java
index 6a2341f..b0c257d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java
@@ -31,7 +31,7 @@ import org.eclipse.core.runtime.CoreException;
class PDOMCPPFunctionTemplateSpecialization extends PDOMCPPFunctionSpecialization
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner {
- public PDOMCPPFunctionTemplateSpecialization(PDOMLinkage linkage, PDOMNode parent,
+ public PDOMCPPFunctionTemplateSpecialization(PDOMCPPLinkage linkage, PDOMNode parent,
ICPPFunctionTemplate template, PDOMBinding specialized) throws CoreException {
super(linkage, parent, template, specialized);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
index 6d7ae1e..48b114c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
@@ -251,6 +251,22 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
fReturnExpression);
}
}
+
+ class ConfigureFunctionSpecialization implements Runnable {
+ private final PDOMCPPFunctionSpecialization fSpec;
+ private final ICPPEvaluation fReturnExpression;
+
+ public ConfigureFunctionSpecialization(ICPPFunction original, PDOMCPPFunctionSpecialization spec) {
+ fSpec = spec;
+ fReturnExpression = CPPFunction.getReturnExpression(original);
+ postProcesses.add(this);
+ }
+
+ @Override
+ public void run() {
+ fSpec.initData(fReturnExpression);
+ }
+ }
class ConfigureFunctionTemplate implements Runnable {
private final PDOMCPPFunctionTemplate fTemplate;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java
index a54785d..e2cbeba 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java
@@ -30,7 +30,7 @@ class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements ICPPMetho
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunctionInstance.RECORD_SIZE + 0;
- public PDOMCPPMethodInstance(PDOMLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding instantiated)
+ public PDOMCPPMethodInstance(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding instantiated)
throws CoreException {
super(linkage, parent, method, instantiated);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java
index 397fddd..142b6ec 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java
@@ -51,7 +51,7 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
*/
private static final int CV_OFFSET = PDOMCPPAnnotation.MAX_EXTRA_OFFSET + 1;
- public PDOMCPPMethodSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding specialized) throws CoreException {
+ public PDOMCPPMethodSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding specialized) throws CoreException {
super(linkage, parent, method, specialized);
Database db = getDB();