https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96103

            Bug ID: 96103
           Summary: Unclear diagnostic for a function return with
                    "decltype(auto)"
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi, all.

This code, "decltype(auto)" in return type is a c++14 extension and I guess GCC
might diagnose this better. 

$cat test.cc
decltype(auto) foo () {}

$g++ -c -std=c++11 test.cc
test.cc:1:10: error: expected primary-expression before ‘auto’
    1 | decltype(auto) foo () {}
      |          ^~~~
test.cc: In function ‘int foo()’:
test.cc:1:24: warning: no return statement in function returning non-void
[-Wreturn-type]
    1 | decltype(auto) foo () {}
      |                        ^

$g++ -c -std=c++14 test.cc
//emits nothing

While in Clang:
$clang++ -c -std=c++11 test.cc 
test.cc:1:10: warning: 'decltype(auto)' type specifier is a C++14 extension
[-Wc++14-extensions]
decltype(auto) foo () {}
         ^
test.cc:1:1: error: deduced return types are a C++14 extension
decltype(auto) foo () {}
^
1 warning and 1 error generated.

I guess users can not fix the code according to the errors emitted until they
realized this is a C++14 extension. 

Should GCC recognizes the C++14 extension first when parsing this code and then
emits the appropriate diagnostic information?

Thanks,
Haoxin

Reply via email to