3 ms·
> is perfectly valid C++ we're in 2020. $ clang-tidy -checks='cppcoreguidelines-*' foo.cpp /tmp/foo.cpp:10:3: warning: initializing non-owner 'Thing
by jcelerier 6y ago
> is perfectly valid C++
we're in 2020.
$ clang-tidy -checks='cppcoreguidelines-*' foo.cpp
/tmp/foo.cpp:10:3: warning: initializing non-owner 'Thing *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]
Thing* thing = new Thing();
^
/tmp/foo.cpp:12:3: warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead [cppcoreguidelines-owning-memory]
delete thing;
^
/tmp/foo.cpp:10:3: note: variable declared here
Thing* thing = new Thing();
^
- cgrealy 6y agoDoes it compile? Does it run? Yes, therefore it's valid C++. I'm not arguing it's good C++, but saying "C++'s destructor behaviour doesn't work if you don't use C++" in relation to using new and delete is clearly nonsense.