public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/102095] New: Returned reference to temporary not caught by -fsanitize=undefined
@ 2021-08-27 11:28 loximann at gmail dot com
  2021-08-31  8:15 ` [Bug sanitizer/102095] " redi at gcc dot gnu.org
  2021-08-31  8:25 ` jakub at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: loximann at gmail dot com @ 2021-08-27 11:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102095
           Summary: Returned reference to temporary not caught by
                    -fsanitize=undefined
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: loximann at gmail dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

The following code results in undefined behaviour (I believe), but it is not
caught by -fsanitize=undefined:

#include <functional>
#include <iostream>
#include <tuple>

template <typename T>
std::function<const T&()> constant(const T& c) {
  return [c]() noexcept -> const T&{ return c; };
}

template <typename T>
std::function<std::tuple<T>()> zip_good(const std::function<T()>& f) {
  return [f]() { return std::tuple<T>{f()}; };
}

template <typename T>
std::function<std::tuple<T>()> zip_bad(const std::function<T()>& f) {
  return [f]() { return std::tuple{f()}; }; // <- UNDEFINED if T is const ref
}

int main() {
    std::cout << std::get<0>(zip_good(constant(1.0))()) << std::endl;
    std::cout << std::get<0>(zip_bad(constant(1.0))()) << std::endl;
}

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

end of thread, other threads:[~2021-08-31  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 11:28 [Bug sanitizer/102095] New: Returned reference to temporary not caught by -fsanitize=undefined loximann at gmail dot com
2021-08-31  8:15 ` [Bug sanitizer/102095] " redi at gcc dot gnu.org
2021-08-31  8:25 ` jakub 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).