public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61400] New: suffix return type doesn't work for member functions
@ 2014-06-03  4:53 yyc1992 at gmail dot com
  2014-06-03  5:05 ` [Bug c++/61400] suffix return type doesn't work for template member functions with explict specialization yyc1992 at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: yyc1992 at gmail dot com @ 2014-06-03  4:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61400
           Summary: suffix return type doesn't work for member functions
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yyc1992 at gmail dot com

The following code compiles on clang++ but not on g++ 4.9.0.

```
struct A {
    template<int i>
    inline int
    a()
    {
        return 0;
    }
    template<int i>
    inline auto
    b() -> decltype(a<i>())
    {
        return a<i>();
    }
};

int
main()
{
    A a;
    a.b<2>();
}
```

g++ can compile it if I change `decltype(a<i>())` to `decltype(this->a<i>())`

System Info.

ArchLinux x86_64 with [testing] [multilib] and [multilib-testing] enabled.
Using official gcc package from ArchLinux.
Command line to compile the program above

g++/clang++ --std=c++11 gcc.cpp -c

where gcc.cpp is the name of the source file.


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

* [Bug c++/61400] suffix return type doesn't work for template member functions with explict specialization
  2014-06-03  4:53 [Bug c++/61400] New: suffix return type doesn't work for member functions yyc1992 at gmail dot com
@ 2014-06-03  5:05 ` yyc1992 at gmail dot com
  2014-06-03  5:12 ` yyc1992 at gmail dot com
  2014-06-03  9:55 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: yyc1992 at gmail dot com @ 2014-06-03  5:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Yichao Yu <yyc1992 at gmail dot com> ---
Additional info.

It seems that G++ only raise this error when all of the following are met:
1. Both of the functions (the one that uses suffix return type and the one used
in the argument of decltype) must be non-static template member functions.
2. The function used in decltype have to be explicitly specialized using at
least one of the template parameter from the other function. (i.e. there won't
be any error if I replace `decltype(a<i>())` with `decltype(a<0>())` or if the
template argument can be deduced from the function arguments) and the type of
the template argument doesn't seem to matter.


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

* [Bug c++/61400] suffix return type doesn't work for template member functions with explict specialization
  2014-06-03  4:53 [Bug c++/61400] New: suffix return type doesn't work for member functions yyc1992 at gmail dot com
  2014-06-03  5:05 ` [Bug c++/61400] suffix return type doesn't work for template member functions with explict specialization yyc1992 at gmail dot com
@ 2014-06-03  5:12 ` yyc1992 at gmail dot com
  2014-06-03  9:55 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: yyc1992 at gmail dot com @ 2014-06-03  5:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Yichao Yu <yyc1992 at gmail dot com> ---
Sorry I have just noticed that I forgot to include the error message...

```
gcc.cpp: In function 'int main()':
gcc.cpp:20:12: error: no matching function for call to 'A::b()'
     a.b<2>();
            ^
gcc.cpp:20:12: note: candidate is:
gcc.cpp:10:5: note: template<int i> decltype (a<i>()) A::b()
     b() -> decltype(a<i>())
     ^
gcc.cpp:10:5: note:   template argument deduction/substitution failed:
gcc.cpp: In substitution of 'template<int i> decltype (a<i>()) A::b() [with int
i = 2]':
gcc.cpp:20:12:   required from here
gcc.cpp:10:26: error: cannot call member function 'int A::a() [with int i = 2]'
without object
     b() -> decltype(a<i>())
```


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

* [Bug c++/61400] suffix return type doesn't work for template member functions with explict specialization
  2014-06-03  4:53 [Bug c++/61400] New: suffix return type doesn't work for member functions yyc1992 at gmail dot com
  2014-06-03  5:05 ` [Bug c++/61400] suffix return type doesn't work for template member functions with explict specialization yyc1992 at gmail dot com
  2014-06-03  5:12 ` yyc1992 at gmail dot com
@ 2014-06-03  9:55 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2014-06-03  9:55 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Yichao Yu from comment #1)
> 2. The function used in decltype have to be explicitly specialized using at
> least one of the template parameter from the other function. (i.e. there
> won't be any error if I replace `decltype(a<i>())` with `decltype(a<0>())`

That has an explicit template argument list, that's not the same as "explicitly
specialized"

This was fixed a few days ago anyway.

*** This bug has been marked as a duplicate of bug 57543 ***


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

end of thread, other threads:[~2014-06-03  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-03  4:53 [Bug c++/61400] New: suffix return type doesn't work for member functions yyc1992 at gmail dot com
2014-06-03  5:05 ` [Bug c++/61400] suffix return type doesn't work for template member functions with explict specialization yyc1992 at gmail dot com
2014-06-03  5:12 ` yyc1992 at gmail dot com
2014-06-03  9:55 ` redi 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).