Quantcast
Channel: Clang: no warning with -Wdangling-gsl and curly braces initialization, bug in clang? - Stack Overflow
Viewing all articles
Browse latest Browse all 30

Clang: no warning with -Wdangling-gsl and curly braces initialization, bug in clang?

$
0
0

Consider the following snippet:

#include <string>#include <string_view>int main() {  auto str = std::string{};  auto sv1 = std::string_view(str +"!"); // <- warning :)  std::string_view sv2(str +"!");        // <- warning :)  std::string_view sv3 = str +"!";       // <- warning :)  auto sv4 = std::string_view{str +"!"}; // <- no warning :(  std::string_view sv5{str +"!"};        // <- no warning :(}

Compiled with flags -std=c++17 -Wdangling-gsl. Tested in clang 12.0.1 and trunk in compiler explorer.

As expected, in sv1, sv2 and sv3, str +"!" triggers the warning:

Object backing the pointer will be destroyed at the end of the full-expression [-Wdangling-gsl]

However in sv4 and sv5 the same expression, but using {}, does not.

Is this an expected behaviour of using {}? Is this a bug in clang? Am I just missing something?


Viewing all articles
Browse latest Browse all 30

Trending Articles


Vimeo 10.7.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


Presence Quotes – Positive Quotes


EASY COME, EASY GO


Long Distance Relationship Tagalog Love Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Smile Quotes


Tiwala Quotes and Selos Quotes Collections


Love with Heart Breaking Quotes


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Maganda Quotes – tagalog Quotes – Inggit Quotes