clang-tools 22.0.0git
clang::tidy::modernize::ReplaceAutoPtrCheck Class Reference

Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr. More...

#include <ReplaceAutoPtrCheck.h>

Inheritance diagram for clang::tidy::modernize::ReplaceAutoPtrCheck:
[legend]

Public Member Functions

 ReplaceAutoPtrCheck (StringRef Name, ClangTidyContext *Context)
bool isLanguageVersionSupported (const LangOptions &LangOpts) const override
void storeOptions (ClangTidyOptions::OptionMap &Opts) override
void registerMatchers (ast_matchers::MatchFinder *Finder) override
void registerPPCallbacks (const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
void check (const ast_matchers::MatchFinder::MatchResult &Result) override

Detailed Description

Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.

Note that both the std::auto_ptr type and the transfer of ownership are transformed. std::auto_ptr provides two ways to transfer the ownership, the copy-constructor and the assignment operator. Unlike most classes these operations do not 'copy' the resource but they 'steal' it. std::unique_ptr uses move semantics instead, which makes the intent of transferring the resource explicit. This difference between the two smart pointers requires wrapping the copy-ctor and assign-operator with std::move().

For example, given:

std::auto_ptr<int> i, j;
i = j;

This code is transformed to:

std::unique_ptr<in> i, j;
i = std::move(j);

Definition at line 41 of file ReplaceAutoPtrCheck.h.

Constructor & Destructor Documentation

◆ ReplaceAutoPtrCheck()

clang::tidy::modernize::ReplaceAutoPtrCheck::ReplaceAutoPtrCheck ( StringRef Name,
ClangTidyContext * Context )

Definition at line 38 of file ReplaceAutoPtrCheck.cpp.

Member Function Documentation

◆ check()

void clang::tidy::modernize::ReplaceAutoPtrCheck::check ( const ast_matchers::MatchFinder::MatchResult & Result)
override

Definition at line 98 of file ReplaceAutoPtrCheck.cpp.

◆ isLanguageVersionSupported()

bool clang::tidy::modernize::ReplaceAutoPtrCheck::isLanguageVersionSupported ( const LangOptions & LangOpts) const
inlineoverride

Definition at line 44 of file ReplaceAutoPtrCheck.h.

◆ registerMatchers()

void clang::tidy::modernize::ReplaceAutoPtrCheck::registerMatchers ( ast_matchers::MatchFinder * Finder)
override

Definition at line 49 of file ReplaceAutoPtrCheck.cpp.

◆ registerPPCallbacks()

void clang::tidy::modernize::ReplaceAutoPtrCheck::registerPPCallbacks ( const SourceManager & SM,
Preprocessor * PP,
Preprocessor * ModuleExpanderPP )
override

Definition at line 92 of file ReplaceAutoPtrCheck.cpp.

◆ storeOptions()

void clang::tidy::modernize::ReplaceAutoPtrCheck::storeOptions ( ClangTidyOptions::OptionMap & Opts)
override

Definition at line 45 of file ReplaceAutoPtrCheck.cpp.


The documentation for this class was generated from the following files: