diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 942eb318f2c155c4796e1a91b6c7eca1deffba15..b81de8ef9349dedc5657c89d0b0c78014c298bc9 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10365,6 +10365,12 @@ grokvardecl (tree type,
 		    "a non-template variable cannot be %<concept%>");
           return NULL_TREE;
         }
+      else if (!at_namespace_scope_p ())
+	{
+	  error_at (declspecs->locations[ds_concept],
+		    "concept must be defined at namespace scope");
+	  return NULL_TREE;
+	}
       else
         DECL_DECLARED_CONCEPT_P (decl) = true;
       if (!same_type_ignoring_top_level_qualifiers_p (type, boolean_type_node))
diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic16.C b/gcc/testsuite/g++.dg/concepts/diagnostic16.C
new file mode 100644
index 0000000000000000000000000000000000000000..fcba535a876653f8009d723ccd43708b33af21b5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/diagnostic16.C
@@ -0,0 +1,45 @@
+// PR c++/97536
+// { dg-do compile { target concepts } }
+
+template<typename>
+concept C1 = true;
+
+concept C2 = true; // { dg-error "non-template variable cannot be .concept." }
+// { dg-error "concept definition syntax is" "" { target *-*-* } .-1 }
+
+template<typename>
+void fn1 ()
+{
+  concept bar = true; // { dg-error "concept must be defined at namespace scope" }
+// { dg-error "concept definition syntax is" "" { target *-*-* } .-1 }
+}
+
+void fn2 ()
+{
+  concept bar = true; // { dg-error "non-template variable cannot be .concept." }
+// { dg-error "concept definition syntax is" "" { target *-*-* } .-1 }
+}
+
+template<typename>
+void fn3 ()
+{
+  template<typename> // { dg-error "template declaration cannot appear at block scope" }
+  concept bar = true;
+}
+
+void fn4 ()
+{
+  template<typename> // { dg-error "template declaration cannot appear at block scope" }
+  concept bar = true;
+}
+
+void fn5 ()
+{
+  C1 auto x = 42;
+}
+
+template<typename>
+void fn6 ()
+{
+  C1 auto x = 42;
+}