forked from OSchip/llvm-project
[clang] do not emit note for bad conversion when destination type qualifiers are not compatibly include source type qualifiers
llvm.org/PR52014 Differential Revision: https://reviews.llvm.org/D110780
This commit is contained in:
parent
fa32fd3bf7
commit
dbaa408336
|
@ -8914,12 +8914,16 @@ static void emitBadConversionNotes(Sema &S, const InitializedEntity &entity,
|
|||
S.EmitRelatedResultTypeNoteForReturn(destType);
|
||||
}
|
||||
QualType fromType = op->getType();
|
||||
auto *fromDecl = fromType.getTypePtr()->getPointeeCXXRecordDecl();
|
||||
auto *destDecl = destType.getTypePtr()->getPointeeCXXRecordDecl();
|
||||
QualType fromPointeeType = fromType.getCanonicalType()->getPointeeType();
|
||||
QualType destPointeeType = destType.getCanonicalType()->getPointeeType();
|
||||
auto *fromDecl = fromType->getPointeeCXXRecordDecl();
|
||||
auto *destDecl = destType->getPointeeCXXRecordDecl();
|
||||
if (fromDecl && destDecl && fromDecl->getDeclKind() == Decl::CXXRecord &&
|
||||
destDecl->getDeclKind() == Decl::CXXRecord &&
|
||||
!fromDecl->isInvalidDecl() && !destDecl->isInvalidDecl() &&
|
||||
!fromDecl->hasDefinition())
|
||||
!fromDecl->hasDefinition() &&
|
||||
destPointeeType.getQualifiers().compatiblyIncludes(
|
||||
fromPointeeType.getQualifiers()))
|
||||
S.Diag(fromDecl->getLocation(), diag::note_forward_class_conversion)
|
||||
<< S.getASTContext().getTagDeclType(fromDecl)
|
||||
<< S.getASTContext().getTagDeclType(destDecl);
|
||||
|
|
|
@ -9,3 +9,9 @@ template <class C> class A2 {};
|
|||
template <class C> class B2;
|
||||
B2<int> *b2;
|
||||
A2<int> *a2 = b2; // expected-error{{cannot initialize a variable of type 'A2<int> *' with an lvalue of type 'B2<int> *'}}
|
||||
|
||||
typedef struct S s;
|
||||
const s *f();
|
||||
s *g1() { return f(); } // expected-error{{cannot initialize return object of type 's *' (aka 'S *') with an rvalue of type 'const s *' (aka 'const S *')}}
|
||||
|
||||
B1 *g2() { return f(); } // expected-error{{cannot initialize return object of type 'B1 *' with an rvalue of type 'const s *' (aka 'const S *')}}
|
Loading…
Reference in New Issue