https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124059

            Bug ID: 124059
           Summary: [[deprecated]] operator fails to warn when
                    constructing shared pointer
           Product: gcc
           Version: 15.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nwgllspe at memphis dot edu
  Target Milestone: ---

Created attachment 63643
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63643&action=edit
Test source

The following code produces deprecation warnings in two different constructors
but not third involving shared pointer. I was able to get all warnings for
clang++ but not g++.

$ cat main.cpp && g++ -Wall -Wextra main.cpp && ./a.out
#include <iostream>
#include <memory>

struct Test {
    [[deprecated]]
    operator int() { return 1; }
};

struct Test2 {
    Test2(int i) { std::cout << "Test2 constructor called" << std::endl; }
};

int main() {
    auto t = Test();

    auto t1 = Test2(t); // warning
    std::shared_ptr<Test2> t2(new Test2(t)); // warning
    auto t3 = std::make_shared<Test2>(t); // No warning

    return 0;
}

main.cpp: In constructor ‘Test2::Test2(int)’:
main.cpp:10:15: warning: unused parameter ‘i’ [-Wunused-parameter]
   10 |     Test2(int i) { std::cout << "Test2 constructor called" <<
std::endl; }
      |           ~~~~^
main.cpp: In function ‘int main()’:
main.cpp:16:21: warning: ‘Test::operator int()’ is deprecated
[-Wdeprecated-declarations]
   16 |     auto t1 = Test2(t); // warning
      |                     ^
main.cpp:6:5: note: declared here
    6 |     operator int() { return 1; }
      |     ^~~~~~~~
main.cpp:17:41: warning: ‘Test::operator int()’ is deprecated
[-Wdeprecated-declarations]
   17 |     std::shared_ptr<Test2> t2(new Test2(t)); // warning
      |                                         ^
main.cpp:6:5: note: declared here
    6 |     operator int() { return 1; }
      |     ^~~~~~~~
main.cpp:16:10: warning: variable ‘t1’ set but not used
[-Wunused-but-set-variable]
   16 |     auto t1 = Test2(t); // warning
      |          ^~
Test2 constructor called
Test2 constructor called
Test2 constructor called

Reply via email to