diff --git a/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp b/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp index c1e1499f85..8f1511c0ad 100755 --- a/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +++ b/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp @@ -13,9 +13,8 @@ ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions * : _readOnly(false), _verifyATN(options->_verifyATN), _generateRuleBypassTransitions(options->_generateRuleBypassTransitions) {} -const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() { - static const ATNDeserializationOptions* const defaultOptions = new ATNDeserializationOptions(); - return *defaultOptions; +ATNDeserializationOptions ATNDeserializationOptions::getDefaultOptions() { + return ATNDeserializationOptions(); } void ATNDeserializationOptions::makeReadOnly() { diff --git a/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h b/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h index 8b1f9850b7..5372fdcbe7 100755 --- a/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +++ b/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h @@ -22,7 +22,7 @@ class ANTLR4CPP_PUBLIC ATNDeserializationOptions final { ATNDeserializationOptions& operator=(const ATNDeserializationOptions&) = default; - static const ATNDeserializationOptions& getDefaultOptions(); + static ATNDeserializationOptions getDefaultOptions(); bool isReadOnly() const { return _readOnly; } diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg index 6fc4419d02..ab823b2d9e 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg @@ -147,7 +147,7 @@ struct StaticData final { #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -StaticData *LexerStaticData = nullptr; +std::unique_ptr\<StaticData> LexerStaticData; void LexerInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE @@ -175,7 +175,7 @@ void LexerInitialize() { } ); - LexerStaticData = staticData.release(); + LexerStaticData = std::move(staticData); } } @@ -380,7 +380,7 @@ struct StaticData final { #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -StaticData *ParserStaticData = nullptr; +std::unique_ptr\<StaticData> ParserStaticData; void ParserInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE @@ -402,7 +402,7 @@ void ParserInitialize() { } ); - ParserStaticData = staticData.release(); + ParserStaticData = std::move(staticData); } }