Skip to content

Commit bcd51aa

Browse files
committed
Don't try to look up a name containing a dependent type.
Template instantiation can create names that are still dependent, such as `operator T`. Don't assume that they can be looked up immediately, and instead defer lookup for such names until we know what `T` is.
1 parent 18a4da8 commit bcd51aa

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,10 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
27362736
ExprResult Sema::BuildQualifiedDeclarationNameExpr(
27372737
CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo,
27382738
bool IsAddressOfOperand, const Scope *S, TypeSourceInfo **RecoveryTSI) {
2739+
if (NameInfo.getName().isDependentName())
2740+
return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
2741+
NameInfo, /*TemplateArgs=*/nullptr);
2742+
27392743
DeclContext *DC = computeDeclContext(SS, false);
27402744
if (!DC)
27412745
return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),

clang/test/SemaCXX/conversion-function.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,16 @@ struct S {
472472
operator const int() const;
473473
};
474474
}
475+
476+
#if __cplusplus >= 201103L
477+
namespace dependent_conversion_function_id_lookup {
478+
template<typename T> struct A {
479+
operator T();
480+
};
481+
template<typename T> struct B : A<T> {
482+
template<typename U> using Lookup = decltype(&B::operator U);
483+
};
484+
using Result = B<int>::Lookup<int>;
485+
using Result = int (A<int>::*)();
486+
}
487+
#endif

0 commit comments

Comments
 (0)