[PATCH] D47503: Sema: Add a warning for member pointers with incomplete base types.
Peter Collingbourne via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 29 16:00:57 PDT 2018
pcc updated this revision to Diff 149001.
pcc added a comment.
- One more negative test
https://reviews.llvm.org/D47503
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/warn-incomplete-member-pointers.cpp
Index: clang/test/SemaCXX/warn-incomplete-member-pointers.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/warn-incomplete-member-pointers.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -Wincomplete-member-pointers %s
+
+struct S; // expected-note {{forward declaration of 'S'}}
+typedef int S::*foo; // expected-warning {{member pointer has incomplete base type 'S'}}
+
+struct S2 {
+ typedef int S2::*foo;
+};
+typedef int S2::*bar;
+
+template <typename T>
+struct S3 {
+ typedef int T::*foo;
+};
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2448,6 +2448,12 @@
return QualType();
}
+ // FIXME: This will cause errors if template instantiation fails.
+ if (!Context.getDiagnostics().isIgnored(diag::warn_memptr_incomplete, Loc) &&
+ !Class->isDependentType() &&
+ !Class->getAsCXXRecordDecl()->isBeingDefined())
+ RequireCompleteType(Loc, Class, diag::warn_memptr_incomplete);
+
// Adjust the default free function calling convention to the default method
// calling convention.
bool IsCtorOrDtor =
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6476,6 +6476,9 @@
def err_bad_memptr_lhs : Error<
"left hand operand to %0 must be a %select{|pointer to }1class "
"compatible with the right hand operand, but is %2">;
+def warn_memptr_incomplete : Warning<
+ "member pointer has incomplete base type %0">,
+ InGroup<DiagGroup<"incomplete-member-pointers">>, DefaultIgnore;
def warn_exception_caught_by_earlier_handler : Warning<
"exception of type %0 will be caught by earlier handler">,
InGroup<Exceptions>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47503.149001.patch
Type: text/x-patch
Size: 1949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180529/9aba5e27/attachment.bin>
More information about the cfe-commits
mailing list