On May 16, 2009, at 6:54 AM, Eli Friedman wrote: > Author: efriedma > Date: Sat May 16 08:54:38 2009 > New Revision: 71946 > > URL: http://llvm.org/viewvc/llvm-project?rev=71946&view=rev > Log: > 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. > > > Modified: > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/lib/Sema/SemaExpr.cpp > > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=71946&r1=71945&r2=71946&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat May 16 08:54:38 2009 > @@ -916,7 +916,13 @@ > 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();
This is slightly too strict in C++, because it's okay to redeclare a variable that has an incomplete type with a complete type (and vice versa). Here's a test case that used to work in C++ but doesn't now: extern int array[10]; extern int array[]; extern int array[10]; > Modified: cfe/trunk/lib/Sema/SemaExpr.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=71946&r1=71945&r2=71946&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) > +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat May 16 08:54:38 2009 > @@ -3727,14 +3727,24 @@ > 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(); > + } > } This looks good. - Doug _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits