c++: ICE with concept defined in function [PR97536]
authorMarek Polacek <polacek@redhat.com>
Mon, 19 Apr 2021 20:21:46 +0000 (16:21 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 19 Apr 2021 20:35:00 +0000 (16:35 -0400)
commit29d8838c5ecaf70ce552fea7639ec1f34adb2e04
tree5d18c2036d00214ef045e3afa9828b3918d52301
parent329d2f0df7d6d22c87ab3338b94caef68139cd58
c++: ICE with concept defined in function [PR97536]

This is an ICE-on-invalid, but I keep seeing it when reducing code so
I'd like to fix it.  We crash on

  template <typename> void forward() {
    concept C = true;
  }

which breaks two requirements:
[temp.concept]/1: A concept is a template ...
[temp.concept]/3: A concept-definition shall inhabit a namespace scope.

This patch adds a test that exercises broken code and fixes the ICE
by checking that a concept-definition is defined at namespace scope.

gcc/cp/ChangeLog:

PR c++/97536
* decl.c (grokvardecl): Given an error when a concept is not defined
at namespace scope.

gcc/testsuite/ChangeLog:

PR c++/97536
* g++.dg/concepts/diagnostic16.C: New test.
gcc/cp/decl.c
gcc/testsuite/g++.dg/concepts/diagnostic16.C [new file with mode: 0644]