Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not error out failing to resolve function in dependend context #339

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8052,6 +8052,34 @@ public void testSfinaeInDefaultArgument() throws Exception {
parseAndCheckBindings();
}

// namespace std {
// template<typename _Tp, typename _Up = _Tp&&> _Up __declval(int);
// template<typename _Tp> _Tp __declval(long);
// template<typename _Tp> auto declval() noexcept -> decltype(__declval<_Tp>(0));
// }
//
// template <typename T>
// using is_augmented_t = decltype (is_augmented (std::declval<T *> ()));
//
// template <typename T, typename = is_augmented_t<T>>
// constexpr T f(T x) { return x; }
//
// template <typename T, typename = is_augmented_t<T>>
// constexpr T g(T x) { return x; }
//
// enum E { E1 = 42 };
// void is_augmented(E *);
//
// void is_augmented(int *);
//
// constexpr int value_via_adl = f(E1); // ADL via enumeration argument finds is_augmented(E*)
// constexpr int value_no_adl = g(int(E1)); // Error: no ADL performed, is_augmented(int*) is not found
public void testSfinaeInDependentContext() throws Exception {
BindingAssertionHelper bh = getAssertionHelper();
bh.assertVariableValue("value_via_adl", 42);
bh.assertProblem("g(int(E1))", 1);
}

// typedef char (&no_tag)[1];
// typedef char (&yes_tag)[2];
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
Expand All @@ -39,6 +41,7 @@
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.dom.parser.CompositeValue;
import org.eclipse.cdt.internal.core.dom.parser.DependentValue;
Expand Down Expand Up @@ -242,8 +245,20 @@ public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) {
EvalFunctionSet functionSet = (EvalFunctionSet) args[0];
args[0] = functionSet.resolveFunction(Arrays.copyOfRange(args, 1, args.length));

// Propagate instantiation errors for SFINAE purposes.
if (args[0] == EvalFixed.INCOMPLETE) {
// Do not error if instantiation context is still a dependent template-id,
// as function set can still be resolved later via ADL.
if (CPPSemantics.getCurrentLookupPoint() instanceof ICPPASTTemplateId templateId) {
for (IASTNode argument : templateId.getTemplateArguments()) {
if (argument instanceof IASTTypeId typeId) {
if (CPPVisitor.createType(typeId) instanceof ICPPTemplateParameter) {
return this;
}
}
}
}

// Propagate instantiation errors for SFINAE purposes.
return args[0];
}

Expand Down