blob: a1d907ab360a877b8416cedd4b45c8c002016629 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s -Winvalid-offsetof
Anders Carlsson6d7f1492009-05-01 23:20:30 +00002
3struct NonPOD {
4 virtual void f();
5 int m;
6};
7
8struct P {
9 NonPOD fieldThatPointsToANonPODType;
10};
11
12void f() {
John McCall7c2342d2010-03-10 11:27:22 +000013 int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{offset of on non-POD type 'P'}}
Anders Carlsson6d7f1492009-05-01 23:20:30 +000014}
15
Eli Friedman16c53782009-12-04 07:18:51 +000016struct Base { int x; };
17struct Derived : Base { int y; };
18int o = __builtin_offsetof(Derived, x); // expected-warning{{offset of on non-POD type}}
Douglas Gregor75b699a2009-12-12 07:25:49 +000019
20const int o2 = sizeof(__builtin_offsetof(Derived, x));
Douglas Gregor8ecdb652010-04-28 22:16:22 +000021
22struct HasArray {
23 int array[17];
24};
25
26// Constant and non-constant offsetof expressions
27void test_ice(int i) {
28 int array0[__builtin_offsetof(HasArray, array[5])];
29 int array1[__builtin_offsetof(HasArray, array[i])]; // expected-error{{variable length arrays are not permitted in C++}}
30}