public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed
@ 2022-02-02 13:19 ethouris at gmail dot com
  2022-02-02 14:17 ` [Bug c++/104343] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ethouris at gmail dot com @ 2022-02-02 13:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104343
           Summary: Too many arguments error reported for a
                    variadic-argument function if std::endl is passed
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ethouris at gmail dot com
  Target Milestone: ---

I have the following definition (requires `<string>` and `<stringstream>`):

```
template <class Stream>
inline Stream& Print(Stream& in) { return in;}

template <class Stream, class Arg1, class... Args>
inline Stream& Print(Stream& sout, Arg1&& arg1, Args&&... args)
{
    sout << arg1;
    return Print(sout, args...);
}

template <class... Args>
inline std::string Sprint(Args&&... args)
{
    std::ostringstream sout;
    Print(sout, args...);
    return sout.str();
}
```

The call

```
sinfo.bufferinfo = Sprint("B: off=", buffer.offset(), " now=",
FormatTime(timeinfo), endl);
```

Reports this error:

```
(5 of 13): error: too many arguments to function 'std::__cxx11::string
Sprint(Args&& ...) [with Args = {}; std::__cxx11::string =
std::__cxx11::basic_string<char>]'
```

Replacing `endl` with `"\n"` fixes the problem.

Might be that I cannot bind `std::endl` to the argument as given here, but the
error report is at least misleading. How can there be "too many arguments"
passed to a function that gets a variable number of arguments?

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

* [Bug c++/104343] Too many arguments error reported for a variadic-argument function if std::endl is passed
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
@ 2022-02-02 14:17 ` rguenth at gcc dot gnu.org
  2022-02-02 17:13 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-02 14:17 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2022-02-02

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Please provide a full compilable testcase.

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

* [Bug c++/104343] Too many arguments error reported for a variadic-argument function if std::endl is passed
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
  2022-02-02 14:17 ` [Bug c++/104343] " rguenth at gcc dot gnu.org
@ 2022-02-02 17:13 ` redi at gcc dot gnu.org
  2022-02-02 17:15 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-02 17:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Your code is invalid. std::endl is an overloaded function, so you can't pass it
as an argument like that. The template argument cannot be deduced.

GCC's error could be improved though.

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

* [Bug c++/104343] Too many arguments error reported for a variadic-argument function if std::endl is passed
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
  2022-02-02 14:17 ` [Bug c++/104343] " rguenth at gcc dot gnu.org
  2022-02-02 17:13 ` redi at gcc dot gnu.org
@ 2022-02-02 17:15 ` redi at gcc dot gnu.org
  2022-02-02 17:31 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-02 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|WAITING                     |NEW

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
When creating the bug you were asked to read https://gcc.gnu.org/bugs which
makes it clear that a proper test case is required, not a snippet of incomplete
code.

Also, GCC 7 has been unsupported for a couple of years.

Here's a complete reproducer:

void endl(char);
void endl(wchar_t);

template <class Stream>
inline Stream& Print(Stream& in) { return in;}

template <class Stream, class Arg1, class... Args>
inline Stream& Print(Stream& sout, Arg1&& arg1, Args&&... args)
{
    return Print(sout, args...);
}

template <class... Args>
inline void Sprint(Args&&... args)
{
    int sout;
    Print(sout, args...);
}

int main()
{
  Sprint("B: off=", 2, " now=", 3, endl);
}

x.C: In function ‘int main()’:
x.C:22:9: error: too many arguments to function ‘void Sprint(Args&& ...) [with
Args = {}]’
   22 |   Sprint("B: off=", 2, " now=", 3, endl);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x.C:14:13: note: declared here
   14 | inline void Sprint(Args&&... args)
      |             ^~~~~~

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

* [Bug c++/104343] Too many arguments error reported for a variadic-argument function if std::endl is passed
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
                   ` (2 preceding siblings ...)
  2022-02-02 17:15 ` redi at gcc dot gnu.org
@ 2022-02-02 17:31 ` redi at gcc dot gnu.org
  2022-02-02 17:33 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-02 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Further reduced:

void endl(char);
void endl(wchar_t);

template <class... Args> inline void Sprint(Args&&...) { }

int main()
{
  Sprint("B: off=", 2, " now=", 3, endl);
}

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

* [Bug c++/104343] Too many arguments error reported for a variadic-argument function if std::endl is passed
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
                   ` (3 preceding siblings ...)
  2022-02-02 17:31 ` redi at gcc dot gnu.org
@ 2022-02-02 17:33 ` redi at gcc dot gnu.org
  2022-02-02 21:25 ` [Bug c++/104343] improved error message for passing overloaded function to variadic-argument function pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-02 17:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Clang gives:

x.C:11:3: error: no matching function for call to 'Sprint'
  Sprint("B: off=", 2, " now=", 3, endl);
  ^~~~~~
x.C:5:13: note: candidate template ignored: substitution failure: deduced
incomplete pack <char const (&)[8], int, char const (&)[6], int, (no value)>
for template parameter 'Args'
inline void Sprint(Args&&... args)
            ^
1 error generated.


The "(no value)" is the clue here.

EDG says:

"x.C", line 11: error: no instance of function template "Sprint" matches the
          argument list
            argument types are: (const char [8], int, const char [6], int,
                      <unknown-type>)
    Sprint("B: off=", 2, " now=", 3, endl);
    ^

1 error detected in the compilation of "x.C".


I'm surprised GCC doesn't say "<unresolved overloaded function type>"

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

* [Bug c++/104343] improved error message for passing overloaded function to variadic-argument function
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
                   ` (4 preceding siblings ...)
  2022-02-02 17:33 ` redi at gcc dot gnu.org
@ 2022-02-02 21:25 ` pinskia at gcc dot gnu.org
  2024-03-16 18:11 ` [Bug c++/104343] improved error message for passing overloaded function to variadic(templated)-argument function pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-02 21:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
            Summary|Too many arguments error    |improved error message for
                   |reported for a              |passing overloaded function
                   |variadic-argument function  |to variadic-argument
                   |if std::endl is passed      |function

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

* [Bug c++/104343] improved error message for passing overloaded function to variadic(templated)-argument function
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
                   ` (5 preceding siblings ...)
  2022-02-02 21:25 ` [Bug c++/104343] improved error message for passing overloaded function to variadic-argument function pinskia at gcc dot gnu.org
@ 2024-03-16 18:11 ` pinskia at gcc dot gnu.org
  2024-03-17  6:07 ` f.heckenbach@fh-soft.de
  2024-03-17  6:17 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-16 18:11 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |f.heckenbach@fh-soft.de

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 114362 has been marked as a duplicate of this bug. ***

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

* [Bug c++/104343] improved error message for passing overloaded function to variadic(templated)-argument function
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
                   ` (6 preceding siblings ...)
  2024-03-16 18:11 ` [Bug c++/104343] improved error message for passing overloaded function to variadic(templated)-argument function pinskia at gcc dot gnu.org
@ 2024-03-17  6:07 ` f.heckenbach@fh-soft.de
  2024-03-17  6:17 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: f.heckenbach@fh-soft.de @ 2024-03-17  6:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Frank Heckenbach <f.heckenbach@fh-soft.de> ---
#3 points out "Also, GCC 7 has been unsupported for a couple of years." My new
"duplicate" report shows that the problem still exists with current versions.
You might want to update the version number to make it clear that it's still
relevant.

(Actually, I think it would be good if bugzilla would automatically set the
version to the latest one when merging, but I don't know how hard this would be
to implement.)

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

* [Bug c++/104343] improved error message for passing overloaded function to variadic(templated)-argument function
  2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
                   ` (7 preceding siblings ...)
  2024-03-17  6:07 ` f.heckenbach@fh-soft.de
@ 2024-03-17  6:17 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-17  6:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Frank Heckenbach from comment #7)
> #3 points out "Also, GCC 7 has been unsupported for a couple of years." My
> new "duplicate" report shows that the problem still exists with current
> versions. You might want to update the version number to make it clear that
> it's still relevant.


That comment about gcc 7 years being unsupported was partly due tobthe original
bug report being not clear at what the issue was and being reported against a
much older release than what was st the time being supported.

I will update the known to fail field tomorrow to include new versions so it is
more obvious it still fails. Note the version field is more for against when it
was reported rather than if it fails with the latest version.

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

end of thread, other threads:[~2024-03-17  6:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 13:19 [Bug c++/104343] New: Too many arguments error reported for a variadic-argument function if std::endl is passed ethouris at gmail dot com
2022-02-02 14:17 ` [Bug c++/104343] " rguenth at gcc dot gnu.org
2022-02-02 17:13 ` redi at gcc dot gnu.org
2022-02-02 17:15 ` redi at gcc dot gnu.org
2022-02-02 17:31 ` redi at gcc dot gnu.org
2022-02-02 17:33 ` redi at gcc dot gnu.org
2022-02-02 21:25 ` [Bug c++/104343] improved error message for passing overloaded function to variadic-argument function pinskia at gcc dot gnu.org
2024-03-16 18:11 ` [Bug c++/104343] improved error message for passing overloaded function to variadic(templated)-argument function pinskia at gcc dot gnu.org
2024-03-17  6:07 ` f.heckenbach@fh-soft.de
2024-03-17  6:17 ` 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).