Skip to content

Commit

Permalink
Don't try to look up a name containing a dependent type.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zygoloid committed Dec 13, 2022
1 parent 18a4da8 commit bcd51aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaExpr.cpp
Expand Up @@ -2736,6 +2736,10 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
ExprResult Sema::BuildQualifiedDeclarationNameExpr(
CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo,
bool IsAddressOfOperand, const Scope *S, TypeSourceInfo **RecoveryTSI) {
if (NameInfo.getName().isDependentName())
return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
NameInfo, /*TemplateArgs=*/nullptr);

DeclContext *DC = computeDeclContext(SS, false);
if (!DC)
return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaCXX/conversion-function.cpp
Expand Up @@ -472,3 +472,16 @@ struct S {
operator const int() const;
};
}

#if __cplusplus >= 201103L
namespace dependent_conversion_function_id_lookup {
template<typename T> struct A {
operator T();
};
template<typename T> struct B : A<T> {
template<typename U> using Lookup = decltype(&B::operator U);
};
using Result = B<int>::Lookup<int>;
using Result = int (A<int>::*)();
}
#endif

0 comments on commit bcd51aa

Please sign in to comment.