public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96103] New: Unclear diagnostic for a function return with "decltype(auto)"
@ 2020-07-07 17:41 haoxintu at gmail dot com
  2020-07-07 20:19 ` [Bug c++/96103] " mpolacek at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: haoxintu at gmail dot com @ 2020-07-07 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-07 17:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-07 17:41 [Bug c++/96103] New: Unclear diagnostic for a function return with "decltype(auto)" haoxintu at gmail dot com
2020-07-07 20:19 ` [Bug c++/96103] " mpolacek at gcc dot gnu.org
2020-07-07 21:13 ` mpolacek at gcc dot gnu.org
2020-07-08 13:33 ` cvs-commit at gcc dot gnu.org
2020-07-08 13:34 ` mpolacek at gcc dot gnu.org
2021-09-07 17:07 ` pinskia at gcc dot gnu.org
2021-09-07 17:07 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).