diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index e9ccbec..b08705c 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -2576,7 +2576,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
         }
       }
 
-      if (LangOpts.CPlusPlus && D.getDeclSpec().isTypeSpecOwned()) {
+      if (LangOpts.CPlusPlus && D.getDeclSpec().isTypeSpecOwned() &&
+          D.getDeclSpec().getRepAsDecl()) {
         // C++ [dcl.fct]p6:
         //   Types shall not be defined in return or parameter types.
         TagDecl *Tag = cast<TagDecl>(D.getDeclSpec().getRepAsDecl());
diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp
index ec1ccbf..11a08d9 100644
--- a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp
+++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp
@@ -6,3 +6,6 @@ void A::f(enum { e2 }) {} // expected-error{{can not be defined in a parameter}}
 
 enum { e3 } A::g() { } // expected-error{{can not be defined in the result type}} \
 // expected-error{{out-of-line definition}}
+
+struct B {}; // expected-note{{previous definition is here}}
+struct B {} f(); // expected-error{{redefinition of 'B'}}
