[Bug c++/105976] New: -Wuse-after-free warning with std::shared_ptr<std::shared_ptr<T>[]>::reset
anabelsmruggiero at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Jun 14 16:17:28 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105976
Bug ID: 105976
Summary: -Wuse-after-free warning with
std::shared_ptr<std::shared_ptr<T>[]>::reset
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: anabelsmruggiero at gmail dot com
Target Milestone: ---
GCC 12.1 emits a use-after-free warning when calling
std::shared_ptr<std::shared_ptr<T>[]>::reset outside of main:
void testArrOfArr(){
std::shared_ptr<std::shared_ptr< double[] >[]> testPtr;
testPtr.reset(new std::shared_ptr< double[] >[6]);
}
void testArr(){
std::shared_ptr<std::shared_ptr< double >[]> testPtr;
testPtr.reset(new std::shared_ptr< double >[6]);
}
int main(){
// Uncommenting the body of main squelches all warnings
/*
std::shared_ptr<std::shared_ptr< double >[]> testArrPtr;
testArrPtr.reset(new std::shared_ptr< double >[6]);
std::shared_ptr<std::shared_ptr< double[] >[]> testArrOfArrPtr;
testArrOfArrPtr.reset(new std::shared_ptr< double[] >[6]);
*/
}
Compiler arguments: -std=c++20 -Wall -Wextra -O2
This warning occurs at or above -02 and disappears below that.
I also have this repro on Godbolt with a few more additional lines that end up
squelching the warning: https://godbolt.org/z/YaKP985es
More information about the Gcc-bugs
mailing list