https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116678
Bug ID: 116678 Summary: "-Os" triggers [[deprecated]] on a class ctor definition with implementation Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: zetab007 at gmail dot com Target Milestone: --- When using the [[deprecated]] attribute on a class ctor definition with implementation and compiling with "-Os" flag, the deprecation message will be triggered even when the class is not used. test.cpp: class test_class { public: [[deprecated("deprecated ctor without parameter.")]] test_class() { m_var = 1; } test_class(int a) { m_var = a; } ~test_class() {} private: int m_var; }; int main() { return 0; } Compiling with following command gives the deprecation message. g++ -Os -o test.o test.cpp test.cpp: In constructor 'test_class::test_class()': test.cpp:6:31: warning: 'test_class::test_class()' is deprecated: deprecated ctor without parameter. [-Wdeprecated-declarations] 6 | test_class() { m_var = 1; } | ^ test.cpp:6:5: note: declared here 6 | test_class() { m_var = 1; } | ^~~~~~~~~~ test.cpp: In constructor 'test_class::test_class()': test.cpp:6:31: warning: 'test_class::test_class()' is deprecated: deprecated ctor without parameter. [-Wdeprecated-declarations] 6 | test_class() { m_var = 1; } | ^ test.cpp:6:5: note: declared here 6 | test_class() { m_var = 1; } | ^~~~~~~~~~ When compiling without "-Os" flag, everything is fine. This seems only happen on windows. The output of gcc -v: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/lto-wrapper.exe Target: i686-w64-mingw32 Configured with: ../gcc-14.2.0/configure --prefix=/mingw32 --with-local-prefix=/mingw32/local --build=i686-w64-mingw32 --host=i686-w64-mingw32 --target=i686-w64-mingw32 --with-native-system-header-dir=/mingw32/include --libexecdir=/mingw32/lib --enable-bootstrap --enable-checking=release --with-arch=pentium4 --with-tune=generic --enable-languages=c,lto,c++,fortran --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw32 --with-mpfr=/mingw32 --with-mpc=/mingw32 --with-isl=/mingw32 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --disable-sjlj-exceptions --with-dwarf2 --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++ Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 14.2.0 (Rev1, Built by MSYS2 project)