Revert rC330794 and some dependent tiny bug fixes 

See Richard's humbling feedback here: 
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180423/226482.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180423/226486.html

Wish I'd had the patience to solicit the feedback prior to committing :)

Sorry for the noise guys.

Thank you Richard for being the steward that clang deserves!

llvm-svn: 330888
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 5f5d94e..2fad5a1 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -426,7 +426,6 @@
   return Res;
 }
 
-
 template <class T> static bool BadSpecifier(T TNew, T TPrev,
                                             const char *&PrevSpec,
                                             unsigned &DiagID,
@@ -492,6 +491,7 @@
   }
   llvm_unreachable("Unknown typespec!");
 }
+
 const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
                                        const PrintingPolicy &Policy) {
   switch (T) {
@@ -969,69 +969,6 @@
   return false;
 }
 
-bool DeclSpec::setConceptSpec(const SourceLocation Loc, const char *&PrevSpec,
-                              unsigned &DiagID, const PrintingPolicy &PP) {
-  assert(Loc.isValid() && "Loc must be valid, since it is used to identify "
-                          "that this function was called before");
-  assert(!ConceptLoc.isValid() &&
-         "how is this called if concept was already encountered and triggered "
-         "ParseConceptDefinition which parses upto the semi-colon");
-
-  PrevSpec = nullptr;
-  if (TypeSpecType != TST_unspecified) {
-    PrevSpec = DeclSpec::getSpecifierName(static_cast<TST>(TypeSpecType), PP);
-	  ClearTypeSpecType();
-  }
-  if (TypeSpecSign != TSS_unspecified) {
-    PrevSpec = DeclSpec::getSpecifierName(static_cast<TSS>(TypeSpecSign));
-	  TypeSpecSign = TSS_unspecified;
-  }
-  if (TypeSpecWidth != TSW_unspecified) {
-    PrevSpec = DeclSpec::getSpecifierName(static_cast<TSW>(TypeSpecWidth));
-	  TypeSpecWidth = TSW_unspecified;
-  }
-  if (StorageClassSpec != SCS_unspecified) {
-    PrevSpec = DeclSpec::getSpecifierName(static_cast<SCS>(StorageClassSpec));
-	  ClearStorageClassSpecs();
-  }
-  if (ThreadStorageClassSpec != TSCS_unspecified) {
-    PrevSpec =
-        DeclSpec::getSpecifierName(static_cast<TSCS>(ThreadStorageClassSpec));
-    ClearStorageClassSpecs();
-  }
-  if (TypeSpecComplex != TSC_unspecified) {
-    PrevSpec = DeclSpec::getSpecifierName(static_cast<TSC>(TypeSpecComplex));
-    TypeSpecComplex = TSC_unspecified;
-  }
-  if (getTypeQualifiers()) {
-	  PrevSpec = DeclSpec::getSpecifierName(static_cast<TQ>(TypeQualifiers));
-    ClearTypeQualifiers();
-  }
-  if (isFriendSpecified()) {
-    PrevSpec = "friend";
-    Friend_specified = false;
-    FriendLoc = SourceLocation();
-  }
-  if (isConstexprSpecified()) {
-    PrevSpec = "constexpr";
-    Constexpr_specified = false;
-    ConstexprLoc = SourceLocation();
-  }
-  if (isInlineSpecified()) {
-    PrevSpec = "inline";
-    FS_inlineLoc = SourceLocation();
-    FS_inline_specified = false;
-  }
-
-  if (PrevSpec) {
-    DiagID = diag::err_invalid_decl_spec_combination;
-  }
-  // We set the concept location regardless of whether an error occurred.
-  DeclRep = nullptr;
-  ConceptLoc = Loc;
-  return PrevSpec; // If this is non-null, an error occurred.
-}
-
 void DeclSpec::SaveWrittenBuiltinSpecs() {
   writtenBS.Sign = getTypeSpecSign();
   writtenBS.Width = getTypeSpecWidth();
@@ -1333,7 +1270,6 @@
   // TODO: return "auto function" and other bad things based on the real type.
 
   // 'data definition has no type or storage class'?
-
 }
 
 bool DeclSpec::isMissingDeclaratorOk() {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index acbec1a..1bcc932 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4212,12 +4212,6 @@
                                  MultiTemplateParamsArg TemplateParams,
                                  bool IsExplicitInstantiation,
                                  RecordDecl *&AnonRecord) {
-
-  // We don't need to do any additional declspecifier checking on concept
-  // definitions since that should already have been done when the concept kw
-  // location was set within DS.
-  if (DS.isConceptSpecified()) return DS.getRepAsConcept();
-  
   Decl *TagD = nullptr;
   TagDecl *Tag = nullptr;
   if (DS.getTypeSpecType() == DeclSpec::TST_class ||
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0fc399a..678f6af 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9467,7 +9467,7 @@
     NonTemplateTarget = TargetTD->getTemplatedDecl();
 
   UsingShadowDecl *Shadow;
-  if (!isa<ConceptDecl>(Target) && isa<CXXConstructorDecl>(NonTemplateTarget)) {
+  if (isa<CXXConstructorDecl>(NonTemplateTarget)) {
     bool IsVirtualBase =
         isVirtualDirectBase(cast<CXXRecordDecl>(CurContext),
                             UD->getQualifier()->getAsRecordDecl());
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f3cb04a..190dd07 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -232,11 +232,9 @@
     } else {
       assert(isa<ClassTemplateDecl>(TD) || isa<TemplateTemplateParmDecl>(TD) ||
              isa<TypeAliasTemplateDecl>(TD) || isa<VarTemplateDecl>(TD) ||
-             isa<BuiltinTemplateDecl>(TD) || isa<ConceptDecl>(TD));
+             isa<BuiltinTemplateDecl>(TD));
       TemplateKind =
-          isa<VarTemplateDecl>(TD) ? TNK_Var_template :
-          isa<ConceptDecl>(TD) ? TNK_Concept_template :
-          TNK_Type_template;
+          isa<VarTemplateDecl>(TD) ? TNK_Var_template : TNK_Type_template;
     }
   }
 
@@ -3036,8 +3034,7 @@
 
   TemplateDecl *Template = Name.getAsTemplateDecl();
   if (!Template || isa<FunctionTemplateDecl>(Template) ||
-      isa<VarTemplateDecl>(Template) ||
-      isa<ConceptDecl>(Template)) {
+      isa<VarTemplateDecl>(Template)) {
     // We might have a substituted template template parameter pack. If so,
     // build a template specialization type for it.
     if (Name.getAsSubstTemplateTemplateParmPack())
@@ -3991,18 +3988,6 @@
                                   /*FoundD=*/nullptr, TemplateArgs);
 }
 
-ExprResult
-Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
-                             const DeclarationNameInfo &NameInfo,
-                             ConceptDecl *Template,
-                             SourceLocation TemplateLoc,
-                             const TemplateArgumentListInfo *TemplateArgs) {
-  // TODO: Do concept specialization here.
-  Diag(Template->getLocation(), diag::err_concept_feature_unimplemented)
-      << "can not form concept template-id";
-  return ExprError();
-}
-
 ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,
                                      SourceLocation TemplateKWLoc,
                                      LookupResult &R,
@@ -7713,61 +7698,6 @@
   return NewDecl;
 }
 
-ConceptDecl *Sema::ActOnConceptDefinition(Scope *S,
-    MultiTemplateParamsArg TemplateParameterLists, IdentifierInfo *Name,
-    SourceLocation NameLoc, Expr *ConstraintExpr) {
-  // C++2a [temp.concept]p3:
-  // A concept-definition shall appear in the global scope or in a namespace
-  // scope.
-  assert(
-      CurContext->isFileContext() &&
-      "We check during parsing that 'concept's only occur at namespace scope");
-
-  // Forbid any prior declaration of this name within the current namespace.
-  LookupResult Previous(*this,
-                        DeclarationNameInfo(DeclarationName(Name), NameLoc),
-                        LookupOrdinaryName);
-  LookupName(Previous, S);
-  if (!Previous.empty()) {
-    const NamedDecl *PrevDecl = Previous.getRepresentativeDecl();
-    if (PrevDecl->getDeclContext()->Equals(CurContext)) {
-      if (Previous.isSingleResult() &&
-          isa<ConceptDecl>(Previous.getFoundDecl())) {
-        Diag(NameLoc, diag::err_redefinition) << Name;
-      } else {
-        Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
-      }
-      Diag(PrevDecl->getLocation(), diag::note_previous_decl) << PrevDecl;
-      return nullptr;
-    }
-  }
-
-  ConceptDecl *NewDecl = ConceptDecl::Create(Context, CurContext, NameLoc,
-                                             Name, TemplateParameterLists[0],
-                                             ConstraintExpr);
-
-  if (!NewDecl)
-    return nullptr;
-
-  if (NewDecl->getAssociatedConstraints()) {
-    // C++2a [temp.concept]p4:
-    // A concept shall not have associated constraints.
-    // TODO: Make a test once we have actual associated constraints.
-    Diag(NameLoc, diag::err_concept_no_associated_constraints);
-    NewDecl->setInvalidDecl();
-  }
-
-  assert((S->isTemplateParamScope() || !TemplateParameterLists[0]->size()) &&
-         "Not in template param scope?");
-  assert(S->getParent() && !S->getParent()->isTemplateParamScope() &&
-         "Parent scope should exist and not be template parameter.");
-
-  ActOnDocumentableDecl(NewDecl);
-  PushOnScopeChains(NewDecl, S->getParent(), /*AddToContext=*/true);
-
-  return NewDecl;
-}
-
 /// \brief Strips various properties off an implicit instantiation
 /// that has just been explicitly specialized.
 static void StripImplicitInstantiation(NamedDecl *D) {
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 0ebcb03..a7883c6 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3073,11 +3073,6 @@
   return nullptr;
 }
 
-Decl *TemplateDeclInstantiator::VisitConceptDecl(ConceptDecl *D) {
-  llvm_unreachable("Concept definitions cannot reside inside a template");
-  return nullptr;
-}
-
 Decl *TemplateDeclInstantiator::VisitDecl(Decl *D) {
   llvm_unreachable("Unexpected decl");
 }