Skip to content

Commit

Permalink
Fix covariance detection on sugared types
Browse files Browse the repository at this point in the history
  • Loading branch information
bolshakov-a committed Jan 26, 2024
1 parent fb64833 commit 043c0c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion iwyu_ast_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ bool HasCovariantReturnType(const CXXMethodDecl* method_decl) {
// of where return type differs is when they're actually covariant.
// That is, if Clang can already compile this code without errors, and
// return types differ, it can only be due to covariance.
if ((*it)->getReturnType() != derived_return_type)
if ((*it)->getReturnType().getCanonicalType() !=
derived_return_type.getCanonicalType())
return true;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/cxx/cvr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

class Base;

namespace ns {
using ::Base;
}

class ReturnsBase {
virtual Base* non_covariant() = 0;
virtual ns::Base* non_covariant_sugared() = 0;

virtual Base* covariant_derived() = 0;
virtual const Class* covariant_cv_qual() = 0;
Expand All @@ -28,6 +33,12 @@ class ReturnsDerived : public ReturnsBase {
return 0;
}

static Base b;

virtual decltype(b)* non_covariant_sugared() {
return 0;
}

// C++ [class.virtual]p7, second bullet
// Trigger covariant return types:
// Base is an unambiguous and accessible direct or indirect base class of
Expand Down

0 comments on commit 043c0c8

Please sign in to comment.