d: Warn when declared size of a special enum does not match its intrinsic type.
commit3ad9313a2e28287aa350d9dc3ea7746d8302662d
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 5 Jun 2023 16:30:12 +0000 (5 18:30 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 5 Jun 2023 16:49:37 +0000 (5 18:49 +0200)
treed4e55b4d72f35dc9181c44e5938ea617305fb287
parent108ff03bac3c440db792fcc61d6247e75b56a572
d: Warn when declared size of a special enum does not match its intrinsic type.

All special enums have declarations in the D runtime library, but the
compiler will recognize and treat them specially if declared in any
module.  When the underlying base type of a special enum is a different
size to its matched intrinsic, then this can cause undefined behavior at
runtime.  Detect and warn about when such a mismatch occurs.

gcc/d/ChangeLog:

* gdc.texi (Warnings): Document -Wextra and -Wmismatched-special-enum.
* implement-d.texi (Special Enums): Add reference to warning option
-Wmismatched-special-enum.
* lang.opt: Add -Wextra and -Wmismatched-special-enum.
* types.cc (TypeVisitor::visit (TypeEnum *)): Warn when declared
special enum size mismatches its intrinsic type.

gcc/testsuite/ChangeLog:

* gdc.dg/Wmismatched_enum.d: New test.
gcc/d/gdc.texi
gcc/d/implement-d.texi
gcc/d/lang.opt
gcc/d/types.cc
gcc/testsuite/gdc.dg/Wmismatched_enum.d [new file with mode: 0644]