[cfe-dev] g++.old-deja/g++.eh/spec7.C allow simple throw specs on pointers

SENTHIL KUMAR THANGAVELU senthil.t at samsung.com
Tue Jul 30 04:04:40 PDT 2013


 Hello all,
    There is a test case in gcc test suite g++.old-deja/g++.eh/spec7.C that causes compilation error in clang. I used latest clang git trunk. g++ 4.7.2 accepts this test case without any compilation error.

spec7.C:13:15: error: exception specification in declaration does not match previous declaration
void (A::* A::pmf)() = &A::g;
              ^
spec7.C:10:20: note: previous declaration is here
  static void (A::*pmf)() throw ();
                   ^
I can find the test case has been modified earlier to suit clang in this link https://llvm.org/viewvc/llvm-project/clang-tests/trunk/gcc-4_2-testsuite/src/g%2B%2B.old-deja/g%2B%2B.eh/spec7.C?sortby=date&r1=109903&r2=127628&pathrev=127628

Couldn't find other references as to why the test case was changed. Anyone can share the history of this issue?
The question I have is, is the test case's expectation to ignore throw specs on function pointers correct ?

Test case:
// { dg-do run  }
// Test that we allow simple throw specs on pointers.
void f() throw () { }
void (*pf)() throw () = f;
struct A
{
  void g() throw () { }
  static void (A::*pmf)() throw ();
};
void (A::* A::pmf)() = &A::g;
int main()
{
  pf ();
  A a;
  (a.*A::pmf)();
}

Added a small patch which avoids the compilation error. If the test case's expectation is correct then I will forward the patch to cfe-commits.
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 3df0472..7df7127 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -631,9 +631,8 @@ void Sema::MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old) {
   } else if (const PointerType *P = NewType->getAs<PointerType>()) {
     NewType = P->getPointeeType();
     OldType = OldType->getAs<PointerType>()->getPointeeType();
-  } else if (const MemberPointerType *M = NewType->getAs<MemberPointerType>()) {
-    NewType = M->getPointeeType();
-    OldType = OldType->getAs<MemberPointerType>()->getPointeeType();
+  } else if (NewType->getAs<MemberPointerType>()) {
+    return;
   }

Regards
Senthil Kumar




More information about the cfe-dev mailing list