summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-05-16 13:54:38 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-05-16 13:54:38 +0000
commit168fe15b0d22b17d09965a9979a30be9eda7902d (patch)
treeabace111d091b679bdccff1e7ea9d6abf73d2e86 /clang
parente2cad6501576dbcdebb9e7c597c5fdcf620728d7 (diff)
downloadbcm5719-llvm-168fe15b0d22b17d09965a9979a30be9eda7902d.tar.gz
bcm5719-llvm-168fe15b0d22b17d09965a9979a30be9eda7902d.zip
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. llvm-svn: 71946
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp8
-rw-r--r--clang/lib/Sema/SemaExpr.cpp26
2 files changed, 25 insertions, 9 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 077658c624d..2847dc10143 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/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/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4145be6ab76..77902d55130 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/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)
OpenPOWER on IntegriCloud