Skip to content

[clang-tidy] bugprone-throw-keyword-missing on default member initializer: "did you mean 'throw shared_ptr'?"Β #129675

@N-Dekker

Description

@N-Dekker

Using LLVM 19.1.7, I encountered a false positive bugprone-throw-keyword-missing from ITK's itkExceptionObject.h, which can be reproduced as follows:

#include <exception>
#include <memory>

class MyException : public std::exception
{
public:
  MyException() = default;
private:
  class NestedData;
  std::shared_ptr<NestedData> m_shared_data{};
};

class Bug : public MyException
{
public:
  Bug()
  {
    // Non-defaulted default constructor.
  }
};

Output:

warning: suspicious exception object created but not thrown; did you mean 'throw shared_ptr'? [bugprone-throw-keyword-missing]
   10 |   std::shared_ptr<NestedData> m_shared_data{};
      |                                            ^

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions