[clang] [Clang] Only compare template params of potential overload after checking their decl context (PR #78139)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 15 03:06:55 PST 2024
================
@@ -1259,6 +1259,40 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
return true;
+ // Is the function New an overload of the function Old?
+ QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
+ QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
+
+ // Compare the signatures (C++ 1.3.10) of the two functions to
+ // determine whether they are overloads. If we find any mismatch
+ // in the signature, they are overloads.
+
+ // If either of these functions is a K&R-style function (no
+ // prototype), then we consider them to have matching signatures.
+ if (isa<FunctionNoProtoType>(OldQType.getTypePtr()) ||
+ isa<FunctionNoProtoType>(NewQType.getTypePtr()))
+ return false;
+
+ const FunctionProtoType *OldType = cast<FunctionProtoType>(OldQType);
+ const FunctionProtoType *NewType = cast<FunctionProtoType>(NewQType);
----------------
tbaederr wrote:
```suggestion
const auto *OldType = cast<FunctionProtoType>(OldQType);
const auto *NewType = cast<FunctionProtoType>(NewQType);
```
https://github.com/llvm/llvm-project/pull/78139
More information about the cfe-commits
mailing list