@@ -79,6 +79,27 @@ static QualType getNonTemplateAlias(QualType QT) {
7979 return QT;
8080}
8181
82+ static QualType getReplacementCastType (const Expr *CondLhs, const Expr *CondRhs,
83+ QualType ComparedType) {
84+ QualType LhsType = CondLhs->getType ();
85+ QualType RhsType = CondRhs->getType ();
86+ QualType LhsCanonicalType =
87+ LhsType.getCanonicalType ().getNonReferenceType ().getUnqualifiedType ();
88+ QualType RhsCanonicalType =
89+ RhsType.getCanonicalType ().getNonReferenceType ().getUnqualifiedType ();
90+ QualType GlobalImplicitCastType;
91+ if (LhsCanonicalType != RhsCanonicalType) {
92+ if (llvm::isa<IntegerLiteral>(CondRhs)) {
93+ GlobalImplicitCastType = getNonTemplateAlias (LhsType);
94+ } else if (llvm::isa<IntegerLiteral>(CondLhs)) {
95+ GlobalImplicitCastType = getNonTemplateAlias (RhsType);
96+ } else {
97+ GlobalImplicitCastType = getNonTemplateAlias (ComparedType);
98+ }
99+ }
100+ return GlobalImplicitCastType;
101+ }
102+
82103static std::string createReplacement (const Expr *CondLhs, const Expr *CondRhs,
83104 const Expr *AssignLhs,
84105 const SourceManager &Source,
@@ -92,18 +113,8 @@ static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs,
92113 const llvm::StringRef AssignLhsStr = Lexer::getSourceText (
93114 Source.getExpansionRange (AssignLhs->getSourceRange ()), Source, LO);
94115
95- QualType GlobalImplicitCastType;
96- QualType LhsType = CondLhs->getType ()
97- .getCanonicalType ()
98- .getNonReferenceType ()
99- .getUnqualifiedType ();
100- QualType RhsType = CondRhs->getType ()
101- .getCanonicalType ()
102- .getNonReferenceType ()
103- .getUnqualifiedType ();
104- if (LhsType != RhsType) {
105- GlobalImplicitCastType = getNonTemplateAlias (BO->getLHS ()->getType ());
106- }
116+ QualType GlobalImplicitCastType =
117+ getReplacementCastType (CondLhs, CondRhs, BO->getLHS ()->getType ());
107118
108119 return (AssignLhsStr + " = " + FunctionName +
109120 (!GlobalImplicitCastType.isNull ()
0 commit comments