ahatanak updated this revision to Diff 76513.
ahatanak added a comment.

I think the non-uncompilable error you mentioned is the one on line 7 of the 
test case and the uncompilable error is the one on line 15. Is that correct? 
The modified test case has only one error (on line 7, which is promoted from a 
warning) and it compiles without any errors if the #pragmas are removed.

It seems to me that the root of the problem is that the template instantiation 
S2<int> is left in an incomplete state and VarDecl s2 in the AST, which is of 
type S2<int>, is marked invalid. As I mentioned in my previous comment, I tried 
to fix this by calling hasUncompilableErrorOccurred instead of 
hasFatalErrorOccurred in InstantiatingTemplate::InstantiatingTemplate, but that 
didn't seem correct as a large number of regression tests failed. What is the 
right way to fix this?

`-FunctionDecl 0x7f889602fa90 <line:19:1, line:22:1> line:19:6 foo1 '_Bool 
(const long long *, int *)'

| -ParmVarDecl 0x7f889602f918 <col:11, col:28> col:28 used a 'const long long 
*' |
| -ParmVarDecl 0x7f889602f9c0 <col:31, col:36> col:36 used b 'int *'            
 |

  `-CompoundStmt 0x7f889602fde0 <col:39, line:22:1>
    `-DeclStmt 0x7f889602fd78 <line:20:3, col:13>
      `-VarDecl 0x7f889602fd18 <col:3, col:11> col:11 invalid s2 
'S2<int>':'struct S2<int>'


https://reviews.llvm.org/D26166

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/instantiate-template-fatal-error.cpp


Index: test/SemaCXX/instantiate-template-fatal-error.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/instantiate-template-fatal-error.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+
+#pragma clang diagnostic fatal "-Wall"
+#pragma clang diagnostic fatal "-Wold-style-cast"
+
+template <class T> bool foo0(const long long *a, T* b) {
+  return a == (const long long*)b; // expected-error {{use of old-style cast}}
+}
+
+template<class T>
+struct S1 {
+};
+
+template<class T>
+struct S2 : S1<T> {
+  bool m1(const long long *a, T *b) const { return foo0(a, b); }
+};
+
+bool foo1(const long long *a, int *b) {
+  S2<int> s2;
+  return s2.m1(a, b);
+}
Index: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -1914,7 +1914,7 @@
   if (cast<DeclContext>(D)->isDependentContext())
     return;
 
-  if (Diags.hasUncompilableErrorOccurred()) {
+  if (Diags.hasUncompilableErrorOccurred() || Diags.hasFatalErrorOccurred()) {
     // Flush out any possibly unreachable diagnostics.
     flushDiagnostics(S, fscope);
     return;


Index: test/SemaCXX/instantiate-template-fatal-error.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/instantiate-template-fatal-error.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+
+#pragma clang diagnostic fatal "-Wall"
+#pragma clang diagnostic fatal "-Wold-style-cast"
+
+template <class T> bool foo0(const long long *a, T* b) {
+  return a == (const long long*)b; // expected-error {{use of old-style cast}}
+}
+
+template<class T>
+struct S1 {
+};
+
+template<class T>
+struct S2 : S1<T> {
+  bool m1(const long long *a, T *b) const { return foo0(a, b); }
+};
+
+bool foo1(const long long *a, int *b) {
+  S2<int> s2;
+  return s2.m1(a, b);
+}
Index: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -1914,7 +1914,7 @@
   if (cast<DeclContext>(D)->isDependentContext())
     return;
 
-  if (Diags.hasUncompilableErrorOccurred()) {
+  if (Diags.hasUncompilableErrorOccurred() || Diags.hasFatalErrorOccurred()) {
     // Flush out any possibly unreachable diagnostics.
     flushDiagnostics(S, fscope);
     return;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to