public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96115] New: Char literal, decays to a pointer when passed to function pointer
@ 2020-07-08 14:21 boris_oncev at hotmail dot com
  2020-07-08 15:45 ` [Bug c++/96115] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: boris_oncev at hotmail dot com @ 2020-07-08 14:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96115
           Summary: Char literal, decays to a pointer when passed to
                    function pointer
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: boris_oncev at hotmail dot com
  Target Milestone: ---

Example code:
struct SL{
    template <int N>
    SL(const char (&Str)[N]) {}
};

int foo(SL x) {
    return 2;
}

int main() {
    int (*f)(SL) = &foo;
    foo("asd"); // works fine
    f("asd"); // error could not convert '(const char*) to SL
}

Godbot link:
https://godbolt.org/z/vo8lOf

works on other compilers clang, msvc and icc

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

* [Bug c++/96115] Char literal, decays to a pointer when passed to function pointer
  2020-07-08 14:21 [Bug c++/96115] New: Char literal, decays to a pointer when passed to function pointer boris_oncev at hotmail dot com
@ 2020-07-08 15:45 ` redi at gcc dot gnu.org
  2020-11-03 15:47 ` ldalessandro at gmail dot com
  2021-12-17  6:09 ` [Bug c++/96115] string " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-08 15:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-07-08
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

* [Bug c++/96115] Char literal, decays to a pointer when passed to function pointer
  2020-07-08 14:21 [Bug c++/96115] New: Char literal, decays to a pointer when passed to function pointer boris_oncev at hotmail dot com
  2020-07-08 15:45 ` [Bug c++/96115] " redi at gcc dot gnu.org
@ 2020-11-03 15:47 ` ldalessandro at gmail dot com
  2021-12-17  6:09 ` [Bug c++/96115] string " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ldalessandro at gmail dot com @ 2020-11-03 15:47 UTC (permalink / raw)
  To: gcc-bugs

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

Luke Dalessandro <ldalessandro at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ldalessandro at gmail dot com

--- Comment #1 from Luke Dalessandro <ldalessandro at gmail dot com> ---
This continues to be a problem in gcc trunk, and impacts real code that
attempts to use `std::span` arguments.

Templates are not necessary to reproduce this behavior.

https://godbolt.org/z/PYreGK

```
struct span
{
    span( int (&)[2] ) {}
};

bool foo(span) {
    return true;
}

bool baz(bool (&op)(span), int i, int j) {
    int array[] = {i, j};
    int (&ref)[2] = array;
    return op(ref);
}

auto x = baz(foo, 1, 2);
```

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

* [Bug c++/96115] string literal, decays to a pointer when passed to function pointer
  2020-07-08 14:21 [Bug c++/96115] New: Char literal, decays to a pointer when passed to function pointer boris_oncev at hotmail dot com
  2020-07-08 15:45 ` [Bug c++/96115] " redi at gcc dot gnu.org
  2020-11-03 15:47 ` ldalessandro at gmail dot com
@ 2021-12-17  6:09 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17  6:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=95596

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Very similar to PR 95596.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 14:21 [Bug c++/96115] New: Char literal, decays to a pointer when passed to function pointer boris_oncev at hotmail dot com
2020-07-08 15:45 ` [Bug c++/96115] " redi at gcc dot gnu.org
2020-11-03 15:47 ` ldalessandro at gmail dot com
2021-12-17  6:09 ` [Bug c++/96115] string " 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).