public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97221] New: Returning an array unexpectedly favors const overload in return value's constructor
@ 2020-09-27 23:05 blubban at gmail dot com
  2020-09-27 23:28 ` [Bug c++/97221] " mpolacek at gcc dot gnu.org
  2020-09-27 23:37 ` blubban at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: blubban at gmail dot com @ 2020-09-27 23:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97221
           Summary: Returning an array unexpectedly favors const overload
                    in return value's constructor
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blubban at gmail dot com
  Target Milestone: ---

struct string {
    const char * m;
    template<int N> string(const char (&str)[N]) { m = "CONST"; }
    template<int N> string(char (&str)[N]) { m = "MUT"; }
};

string foo()
{
    char bar[8];
    return bar;
}

With Clang 10.0.1 -O2 -std=c++11, this returns "MUT".
With GCC 10.2 -O2 -std=c++98, this returns "MUT".
With GCC 7.5 -O2 -std=c++11, this returns "MUT".
With GCC 10.2 -O2 -std=c++11, this returns "CONST".

This one should give same result for every configuration, or at least throw a
warning from -Wc++11-compat, right?

Compiler Explorer: https://godbolt.org/z/r3Yo64

(Context: I encountered this when trying to make my string class distinguish
between string literals and char arrays/pointers, and call sizeof instead of
strlen for the former.)

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

end of thread, other threads:[~2020-09-27 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-27 23:05 [Bug c++/97221] New: Returning an array unexpectedly favors const overload in return value's constructor blubban at gmail dot com
2020-09-27 23:28 ` [Bug c++/97221] " mpolacek at gcc dot gnu.org
2020-09-27 23:37 ` blubban at gmail dot com

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).