]> granicus.if.org Git - clang/commitdiff
Avoid calling mergeTypes in C++. I think these are the correct C++
authorEli Friedman <eli.friedman@gmail.com>
Sat, 16 May 2009 13:54:38 +0000 (13:54 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 16 May 2009 13:54:38 +0000 (13:54 +0000)
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

lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp

index 077658c624d64785637863a3a99ae07c0d8ff532..2847dc10143937da1fcde71f67b971bc8d6c80f2 100644 (file)
@@ -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();
index 4145be6ab7659b80f2695755740c9b009878f527..77902d55130b09c998c17c6374ed4e2d0cac5799 100644 (file)
@@ -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)