public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103297] New: GCC cannot detect out of bounds in constexpr context.
@ 2021-11-17  3:13 unlvsur at live dot com
  2021-11-17 11:33 ` [Bug c++/103297] " unlvsur at live dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: unlvsur at live dot com @ 2021-11-17  3:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103297
           Summary: GCC cannot detect out of bounds in constexpr context.
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: unlvsur at live dot com
  Target Milestone: ---

inline constexpr void out_of_bounds_detector(char const*,char const*) noexcept
{}

inline constexpr bool test() noexcept
{
        char buffer[]="abcde";
        out_of_bounds_detector(buffer,buffer+7);//should give a hard error
        return true;
}
static_assert(test());

while clang and msvc can all detect this correctly.

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

* [Bug c++/103297] GCC cannot detect out of bounds in constexpr context.
  2021-11-17  3:13 [Bug c++/103297] New: GCC cannot detect out of bounds in constexpr context unlvsur at live dot com
@ 2021-11-17 11:33 ` unlvsur at live dot com
  2021-11-17 11:51 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: unlvsur at live dot com @ 2021-11-17 11:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from cqwrteur <unlvsur at live dot com> ---
Another issue

#include<string_view>
#include<string>
#include<cassert>

inline constexpr std::string_view lifetime_detector(std::string const& str)
noexcept
{
        return str;
}

inline constexpr bool test2(std::string_view vw2) noexcept
{
        bool res{true};
        for(auto e : vw2)
                res|=e;
        return true;
}

inline constexpr bool test() noexcept
{
        std::string_view vw{lifetime_detector("abcde12124")};
        return test2(vw);
}
static_assert(test());

int main()
{
        assert(test());
}

This does not get detected at neither compile nor runtime???

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

* [Bug c++/103297] GCC cannot detect out of bounds in constexpr context.
  2021-11-17  3:13 [Bug c++/103297] New: GCC cannot detect out of bounds in constexpr context unlvsur at live dot com
  2021-11-17 11:33 ` [Bug c++/103297] " unlvsur at live dot com
@ 2021-11-17 11:51 ` redi at gcc dot gnu.org
  2021-11-17 11:53 ` redi at gcc dot gnu.org
  2021-11-17 11:57 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-17 11:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
These are two different bugs, and I think there are existing PRs about both of
them.

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

* [Bug c++/103297] GCC cannot detect out of bounds in constexpr context.
  2021-11-17  3:13 [Bug c++/103297] New: GCC cannot detect out of bounds in constexpr context unlvsur at live dot com
  2021-11-17 11:33 ` [Bug c++/103297] " unlvsur at live dot com
  2021-11-17 11:51 ` redi at gcc dot gnu.org
@ 2021-11-17 11:53 ` redi at gcc dot gnu.org
  2021-11-17 11:57 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-17 11:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to cqwrteur from comment #0)
> 	out_of_bounds_detector(buffer,buffer+7);//should give a hard error

This looks like PR 70151

(In reply to cqwrteur from comment #1)
> 	std::string_view vw{lifetime_detector("abcde12124")};
> 	return test2(vw);

This might be PR 70331

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

* [Bug c++/103297] GCC cannot detect out of bounds in constexpr context.
  2021-11-17  3:13 [Bug c++/103297] New: GCC cannot detect out of bounds in constexpr context unlvsur at live dot com
                   ` (2 preceding siblings ...)
  2021-11-17 11:53 ` redi at gcc dot gnu.org
@ 2021-11-17 11:57 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-17 11:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> (In reply to cqwrteur from comment #0)
> > 	out_of_bounds_detector(buffer,buffer+7);//should give a hard error
> 
> This looks like PR 70151

Or its dependent, PR 82876



> (In reply to cqwrteur from comment #1)
> > 	std::string_view vw{lifetime_detector("abcde12124")};
> > 	return test2(vw);
> 
> This might be PR 70331

Or PR 89757 or PR 98675 or PR 96630

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

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17  3:13 [Bug c++/103297] New: GCC cannot detect out of bounds in constexpr context unlvsur at live dot com
2021-11-17 11:33 ` [Bug c++/103297] " unlvsur at live dot com
2021-11-17 11:51 ` redi at gcc dot gnu.org
2021-11-17 11:53 ` redi at gcc dot gnu.org
2021-11-17 11:57 ` 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).