- Notifications
You must be signed in to change notification settings - Fork5
Commit0d0aa5d
committed
Provide some static-assertion functionality on all compilers.
On reflection (especially after noticing how many buildfarm critters have__builtin_types_compatible_p but not _Static_assert), it seems like weought to try a bit harder to make these macros do something everywhere.The initial cut at it would have been no help to code that is compiled onlyon platforms without _Static_assert, for instance; and in any case not allour contributors do their initial coding on the latest gcc version.Some googling about static assertions turns up quite a bit of prior artfor making it work in compilers that lack _Static_assert. The methodthat seems closest to our needs involves defining a struct with a bit-fieldthat has negative width if the assertion condition fails. There seems noreliable way to get the error message string to be output, but throwing acompile error with a confusing message is better than missing the problemaltogether.In the same spirit, if we don't have __builtin_types_compatible_p we can atleast insist that the variable have the same width as the type. This won'tcatch errors such as "wrong pointer type", but it's far better thannothing.In addition to changing the macro definitions, adjust acompile-time-constant Assert in contrib/hstore to use StaticAssertStmt,so we can get some buildfarm coverage on whether that macro behaves sanelyor not. There's surely more places that could be converted, but this isthe first one I came across.1 parentea473fb commit0d0aa5d
2 files changed
+23
-8
lines changedLines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
94 | 94 |
| |
95 | 95 |
| |
96 | 96 |
| |
97 |
| - | |
| 97 | + | |
98 | 98 |
| |
99 | 99 |
| |
100 | 100 |
| |
| |||
180 | 180 |
| |
181 | 181 |
| |
182 | 182 |
| |
183 |
| - | |
| 183 | + | |
| 184 | + | |
184 | 185 |
| |
185 | 186 |
| |
186 | 187 |
| |
|
Lines changed: 20 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
690 | 690 |
| |
691 | 691 |
| |
692 | 692 |
| |
693 |
| - | |
| 693 | + | |
694 | 694 |
| |
695 | 695 |
| |
696 | 696 |
| |
697 | 697 |
| |
698 |
| - | |
| 698 | + | |
699 | 699 |
| |
700 | 700 |
| |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
701 | 705 |
| |
702 | 706 |
| |
703 | 707 |
| |
704 | 708 |
| |
705 | 709 |
| |
706 | 710 |
| |
707 | 711 |
| |
708 |
| - | |
709 |
| - | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
710 | 716 |
| |
711 | 717 |
| |
712 | 718 |
| |
| |||
716 | 722 |
| |
717 | 723 |
| |
718 | 724 |
| |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
719 | 729 |
| |
720 | 730 |
| |
721 | 731 |
| |
| |||
725 | 735 |
| |
726 | 736 |
| |
727 | 737 |
| |
728 |
| - | |
729 |
| - | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
730 | 744 |
| |
731 | 745 |
| |
732 | 746 |
| |
|
0 commit comments
Comments
(0)