--- /dev/null
+// RUN: %clang_cc1 -verify %s
+
+// expected-no-diagnostics
+
+/* WG14 N617: yes
+ * reliable integer division
+ */
+void test(void) {
+ _Static_assert(59 / 4 == 14, "we didn't truncate properly");
+ _Static_assert(59 / -4 == -14, "we didn't truncate properly");
+ _Static_assert(-59 / 4 == -14, "we didn't truncate properly");
+ _Static_assert(-59 / -4 == 14, "we didn't truncate properly");
+
+ // Might as well test % for the quotient.
+ _Static_assert(59 % 4 == 3, "we didn't truncate properly");
+ _Static_assert(59 % -4 == 3, "we didn't truncate properly");
+ _Static_assert(-59 % 4 == -3, "we didn't truncate properly");
+ _Static_assert(-59 % -4 == -3, "we didn't truncate properly");
+
+ // Test the idiom for rounding up.
+ _Static_assert((59 + (4 - 1)) / 4 == 15, "failed to 'round up' with the usual idiom");
+ _Static_assert((59 + (4 - 1)) % 4 == 2, "failed to 'round up' with the usual idiom");
+}
+
--- /dev/null
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-win32 -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-win32 -verify %s
+
+/* WG14 N629: yes
+ * integer constant type rules
+ */
+
+// expected-no-diagnostics
+
+void test_decimal_constants(void) {
+ // Easy cases where the value fits into the type you'd expect.
+ (void)_Generic(2, int : 1);
+ (void)_Generic(2u, unsigned int : 1);
+ (void)_Generic(2l, long : 1);
+ (void)_Generic(2ul, unsigned long : 1);
+ (void)_Generic(2ll, long long : 1);
+ (void)_Generic(2ull, unsigned long long : 1);
+
+#if __INT_WIDTH__ == 16
+ #if __LONG_WIDTH__ > 16
+ (void)_Generic(65536, long : 1);
+ (void)_Generic(65536U, unsigned long : 1);
+ #else
+ (void)_Generic(65536, long long : 1);
+ (void)_Generic(65536U, unsigned long : 1);
+ #endif // __LONG_WIDTH__ > 16
+#elif __INT_WIDTH__ == 32
+ #if __LONG_WIDTH__ > 32
+ (void)_Generic(4294967296, long : 1);
+ (void)_Generic(4294967296U, unsigned long : 1);
+ #else
+ (void)_Generic(4294967296, long long : 1);
+ (void)_Generic(4294967296U, unsigned long long : 1);
+ #endif // __LONG_WIDTH__ > 32
+#endif
+
+#if __LONG_WIDTH__ > 32
+ (void)_Generic(4294967296L, long : 1);
+ (void)_Generic(4294967296U, unsigned long : 1);
+#else
+ (void)_Generic(4294967296L, long long : 1);
+ (void)_Generic(4294967296U, unsigned long long : 1);
+#endif
+}
+
+void test_octal_constants(void) {
+ (void)_Generic(02, int : 1);
+ (void)_Generic(02u, unsigned int : 1);
+ (void)_Generic(02l, long : 1);
+ (void)_Generic(02ul, unsigned long : 1);
+ (void)_Generic(02ll, long long : 1);
+ (void)_Generic(02ull, unsigned long long : 1);
+
+#if __INT_WIDTH__ == 16
+ #if __LONG_WIDTH__ > 16
+ (void)_Generic(0200000, long : 1);
+ (void)_Generic(0200000U, unsigned long : 1);
+ #else
+ (void)_Generic(0200000, long long : 1);
+ (void)_Generic(0200000U, unsigned long : 1);
+ #endif // __LONG_WIDTH__ > 16
+#elif __INT_WIDTH__ == 32
+ #if __LONG_WIDTH__ > 32
+ (void)_Generic(040000000000, long : 1);
+ (void)_Generic(040000000000U, unsigned long : 1);
+ #else
+ (void)_Generic(040000000000, long long : 1);
+ (void)_Generic(040000000000U, unsigned long long : 1);
+ #endif // __LONG_WIDTH__ > 32
+#endif
+
+#if __LONG_WIDTH__ > 32
+ (void)_Generic(040000000000L, long : 1);
+ (void)_Generic(040000000000U, unsigned long : 1);
+#else
+ (void)_Generic(040000000000L, long long : 1);
+ (void)_Generic(040000000000U, unsigned long long : 1);
+#endif
+}
+
+void test_hexadecimal_constants(void) {
+ (void)_Generic(0x2, int : 1);
+ (void)_Generic(0x2u, unsigned int : 1);
+ (void)_Generic(0x2l, long : 1);
+ (void)_Generic(0x2ul, unsigned long : 1);
+ (void)_Generic(0x2ll, long long : 1);
+ (void)_Generic(0x2ull, unsigned long long : 1);
+
+#if __INT_WIDTH__ == 16
+ #if __LONG_WIDTH__ > 16
+ (void)_Generic(0x10000, long : 1);
+ (void)_Generic(0x10000U, unsigned long : 1);
+ #else
+ (void)_Generic(0x10000, long long : 1);
+ (void)_Generic(0x10000U, unsigned long : 1);
+ #endif // __LONG_WIDTH__ > 16
+#elif __INT_WIDTH__ == 32
+ #if __LONG_WIDTH__ > 32
+ (void)_Generic(0x100000000, long : 1);
+ (void)_Generic(0x100000000U, unsigned long : 1);
+ #else
+ (void)_Generic(0x100000000, long long : 1);
+ (void)_Generic(0x100000000U, unsigned long long : 1);
+ #endif // __LONG_WIDTH__ > 32
+#endif
+
+#if __LONG_WIDTH__ > 32
+ (void)_Generic(0x100000000L, long : 1);
+ (void)_Generic(0x100000000U, unsigned long : 1);
+#else
+ (void)_Generic(0x100000000L, long long : 1);
+ (void)_Generic(0x100000000U, unsigned long long : 1);
+#endif
+}
--- /dev/null
+// RUN: %clang_cc1 -verify %s
+
+/* WG14 N736: yes
+ * preprocessor arithmetic done in intmax_t/uintmax_t
+ */
+
+// There is not a standard requirement that this relationships holds. If these
+// asserts fail, it means we have another test scenario to consider.
+_Static_assert(__INTMAX_MAX__ == __LONG_LONG_MAX__,
+ "intmax_t is not the same width as long long?");
+_Static_assert((-__INTMAX_MAX__ - 1) == (-__LONG_LONG_MAX__ - 1LL),
+ "intmax_t is not the same width as long long?");
+_Static_assert(__UINTMAX_MAX__ == (__LONG_LONG_MAX__ * 2ULL + 1ULL),
+ "uintmax_t is not the same width as unsigned long long?");
+
+// Test that arithmetic on the largest positive signed intmax_t works.
+#if 9223372036854775807LL + 0LL != 9223372036854775807LL
+#error "uh oh"
+#endif
+
+// Same for negative.
+#if -9223372036854775807LL - 1LL + 0LL != -9223372036854775807LL - 1LL
+#error "uh oh"
+#endif
+
+// Then test the same for unsigned
+#if 18446744073709551615ULL + 0ULL != 18446744073709551615ULL
+#error "uh oh"
+#endif
+
+// Test that unsigned overflow causes silent wraparound.
+#if 18446744073709551615ULL + 1ULL != 0 // Silently wraps to 0.
+#error "uh oh"
+#endif
+
+#if 0ULL - 1ULL != 18446744073709551615ULL // Silently wraps to 0xFFFF'FFFF'FFFF'FFFF.
+#error "uh oh"
+#endif
+
+// Now test that signed arithmetic that pushes us over a limit is properly
+// diagnosed.
+#if 9223372036854775807LL + 1LL // expected-warning {{integer overflow in preprocessor expression}}
+#endif
+
+#if -9223372036854775807LL - 2LL // expected-warning {{integer overflow in preprocessor expression}}
+#endif
+
<tr>
<td>reliable integer division</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n617.htm">N617</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>universal character names (\u and \U)</td>
<tr>
<td>remove implicit function declaration</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n636.htm">N636</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>preprocessor arithmetic done in intmax_t/uintmax_t</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n736.htm">N736</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>mixed declarations and code</td>
<tr>
<td>integer constant type rules</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n629.htm">N629</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>integer promotion rules</td>