From: Eli Friedman Date: Sat, 16 May 2009 13:54:38 +0000 (+0000) Subject: Avoid calling mergeTypes in C++. I think these are the correct C++ X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88d936b245978038a14b9c7acc062d12bc46096a;p=clang Avoid calling mergeTypes in C++. I think these are the correct C++ alternatives, but please correct me if I'm wrong. I eventually plan to assert in mergeTypes that we aren't in C++ mode because composite types are fundamentally not a part of C++. The remaining callers for code in the regression tests are Sema::WarnConflictingTypedMethods and CodeGenFunction::EmitFunctionProlog; I'm not quite sure what the correct approach is for those callers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71946 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 077658c624..2847dc1014 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -916,7 +916,13 @@ void Sema::MergeVarDecl(VarDecl *New, Decl *OldD) { MergeAttributes(New, Old, Context); // Merge the types - QualType MergedT = Context.mergeTypes(New->getType(), Old->getType()); + QualType MergedT; + if (getLangOptions().CPlusPlus) { + if (Context.hasSameType(New->getType(), Old->getType())) + MergedT = New->getType(); + } else { + MergedT = Context.mergeTypes(New->getType(), Old->getType()); + } if (MergedT.isNull()) { Diag(New->getLocation(), diag::err_redefinition_different_type) << New->getDeclName(); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 4145be6ab7..77902d5513 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3727,14 +3727,24 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex, rex->getType())) return QualType(); - // Pointee types must be compatible. - if (!Context.typesAreCompatible( - Context.getCanonicalType(lpointee).getUnqualifiedType(), - Context.getCanonicalType(rpointee).getUnqualifiedType())) { - Diag(Loc, diag::err_typecheck_sub_ptr_compatible) - << lex->getType() << rex->getType() - << lex->getSourceRange() << rex->getSourceRange(); - return QualType(); + if (getLangOptions().CPlusPlus) { + // Pointee types must be the same: C++ [expr.add] + if (!Context.hasSameUnqualifiedType(lpointee, rpointee)) { + Diag(Loc, diag::err_typecheck_sub_ptr_compatible) + << lex->getType() << rex->getType() + << lex->getSourceRange() << rex->getSourceRange(); + return QualType(); + } + } else { + // Pointee types must be compatible C99 6.5.6p3 + if (!Context.typesAreCompatible( + Context.getCanonicalType(lpointee).getUnqualifiedType(), + Context.getCanonicalType(rpointee).getUnqualifiedType())) { + Diag(Loc, diag::err_typecheck_sub_ptr_compatible) + << lex->getType() << rex->getType() + << lex->getSourceRange() << rex->getSourceRange(); + return QualType(); + } } if (ComplainAboutVoid)