2019-08-30 Jakub Jelinek Backported from mainline 2019-06-21 Jakub Jelinek PR c++/90950 * semantics.c (finish_omp_clauses): Don't reject references to incomplete types if processing_template_decl. * g++.dg/gomp/lastprivate-1.C: New test. --- gcc/cp/semantics.c (revision 272800) +++ gcc/cp/semantics.c (revision 272801) @@ -7315,7 +7315,8 @@ finish_omp_clauses (tree clauses, enum c t = require_complete_type (t); if (t == error_mark_node) remove = true; - else if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE + else if (!processing_template_decl + && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t)) remove = true; } --- gcc/testsuite/g++.dg/gomp/lastprivate-1.C (nonexistent) +++ gcc/testsuite/g++.dg/gomp/lastprivate-1.C (revision 272801) @@ -0,0 +1,16 @@ +// PR c++/90950 +// { dg-do compile } + +template +T +foo (void) +{ + T y = 0; + T &x = y; + #pragma omp parallel for lastprivate (x) + for (int i = 0; i < 8; ++i) + x = i; + return x; +} + +int a = foo ();