Skip to content

Implicitly generated functions for object are not being shown without instantiation #742

@firewave

Description

@firewave

The following code results in:

#include <string>

struct S
{
  std::string s;
};

as

#include <string>

struct S
{
  std::basic_string<char> s;
};

There are no comments added.

The output of the bugprone-exception-escape clang-tidy check indicates that the constructor, destructor and and assignment operator are all implicitly generated (see https://godbolt.org/z/hT8cEK58x):

<source>:3:8: warning: an exception may be thrown in function 'S' which should not throw exceptions [bugprone-exception-escape]
<source>:3:8: warning: an exception may be thrown in function 'operator=' which should not throw exceptions [bugprone-exception-escape]
<source>:3:8: warning: an exception may be thrown in function '~S' which should not throw exceptions [bugprone-exception-escape]

Comments are added if the object is actually being instantiated.

#include <string>

struct S
{
  std::string s;
};

void f()
{
  S s;
}

results in

#include <string>

struct S
{
  std::basic_string<char> s;
  // inline ~S() noexcept = default;
  // inline S() noexcept = default;
};


void f()
{
  S s = S();
}

Requiring the additional code is rather misleading and the assignment operator is also missing (the latter should be split into a separate issue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions