From: Charles Davis Date: Mon, 16 Aug 2010 04:01:50 +0000 (+0000) Subject: Err on incomplete class types in member pointers when compiling for the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d18f9f965bcfe56edcdf9b0d8375ffaad9866b3f;p=clang Err on incomplete class types in member pointers when compiling for the Microsoft C++ ABI, for now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111118 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 28d1f13775..6df16bd300 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -20,6 +20,7 @@ #include "clang/AST/TypeLocVisitor.h" #include "clang/AST/Expr.h" #include "clang/Basic/PartialDiagnostic.h" +#include "clang/Basic/TargetInfo.h" #include "clang/Parse/DeclSpec.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/ErrorHandling.h" @@ -882,6 +883,14 @@ QualType Sema::BuildMemberPointerType(QualType T, QualType Class, return QualType(); } + // In the Microsoft ABI, the class is allowed to be an incomplete + // type. In such cases, the compiler makes a worst-case assumption. + // We make no such assumption right now, so emit an error if the + // class isn't a complete type. + if (Context.Target.getCXXABI() == "microsoft" && + RequireCompleteType(Loc, Class, diag::err_incomplete_type)) + return QualType(); + return Context.getMemberPointerType(T, Class.getTypePtr()); } diff --git a/test/SemaCXX/member-pointer-ms.cpp b/test/SemaCXX/member-pointer-ms.cpp new file mode 100644 index 0000000000..8987f6d66f --- /dev/null +++ b/test/SemaCXX/member-pointer-ms.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -cxx-abi microsoft -fsyntax-only -verify %s + +// Test that we reject pointers to members of incomplete classes (for now) +struct A; //expected-note{{forward declaration of 'A'}} +int A::*pai1; //expected-error{{incomplete type 'A'}} +