Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -Winvalid-offsetof |
Anders Carlsson | 6d7f149 | 2009-05-01 23:20:30 +0000 | [diff] [blame] | 2 | |
| 3 | struct NonPOD { |
| 4 | virtual void f(); |
| 5 | int m; |
| 6 | }; |
| 7 | |
| 8 | struct P { |
| 9 | NonPOD fieldThatPointsToANonPODType; |
| 10 | }; |
| 11 | |
| 12 | void f() { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame^] | 13 | int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{offset of on non-POD type 'P'}} |
Anders Carlsson | 6d7f149 | 2009-05-01 23:20:30 +0000 | [diff] [blame] | 14 | } |
| 15 | |
Eli Friedman | 16c5378 | 2009-12-04 07:18:51 +0000 | [diff] [blame] | 16 | struct Base { int x; }; |
| 17 | struct Derived : Base { int y; }; |
| 18 | int o = __builtin_offsetof(Derived, x); // expected-warning{{offset of on non-POD type}} |
Douglas Gregor | 75b699a | 2009-12-12 07:25:49 +0000 | [diff] [blame] | 19 | |
| 20 | const int o2 = sizeof(__builtin_offsetof(Derived, x)); |