xref: /llvm-project/lldb/test/API/lang/cpp/class_static/main.cpp (revision 22667e3220de5ead353a2148265d841644b63824)
199451b44SJordan Rupprecht // I made this example after noting that I was unable to display an unsized
299451b44SJordan Rupprecht // static class array. It turns out that gcc 4.2 will emit DWARF that correctly
399451b44SJordan Rupprecht // describes the PointType, but it will incorrectly emit debug info for the
499451b44SJordan Rupprecht // "g_points" array where the following things are wrong:
599451b44SJordan Rupprecht //  - the DW_TAG_array_type won't have a subrange info
699451b44SJordan Rupprecht //  - the DW_TAG_variable for "g_points" won't have a valid byte size, so even
799451b44SJordan Rupprecht //    though we know the size of PointType, we can't infer the actual size
899451b44SJordan Rupprecht //    of the array by dividing the size of the variable by the number of
999451b44SJordan Rupprecht //    elements.
1099451b44SJordan Rupprecht 
1199451b44SJordan Rupprecht #include <stdio.h>
1299451b44SJordan Rupprecht 
1399451b44SJordan Rupprecht typedef struct PointType
1499451b44SJordan Rupprecht {
1599451b44SJordan Rupprecht     int x, y;
1699451b44SJordan Rupprecht } PointType;
1799451b44SJordan Rupprecht 
1899451b44SJordan Rupprecht class A
1999451b44SJordan Rupprecht {
2099451b44SJordan Rupprecht public:
2199451b44SJordan Rupprecht     static PointType g_points[];
2299451b44SJordan Rupprecht };
2399451b44SJordan Rupprecht 
24*22667e32SJim Ingham // Make sure similar names don't confuse us:
25*22667e32SJim Ingham 
26*22667e32SJim Ingham class AA
27*22667e32SJim Ingham {
28*22667e32SJim Ingham public:
29*22667e32SJim Ingham   static PointType g_points[];
30*22667e32SJim Ingham };
31*22667e32SJim Ingham 
3299451b44SJordan Rupprecht PointType A::g_points[] =
3399451b44SJordan Rupprecht {
3499451b44SJordan Rupprecht     {    1,    2 },
3599451b44SJordan Rupprecht     {   11,   22 }
3699451b44SJordan Rupprecht };
3799451b44SJordan Rupprecht static PointType g_points[] =
3899451b44SJordan Rupprecht {
3999451b44SJordan Rupprecht     {    3,    4 },
4099451b44SJordan Rupprecht     {   33,   44 }
4199451b44SJordan Rupprecht };
4299451b44SJordan Rupprecht 
43*22667e32SJim Ingham PointType AA::g_points[] =
44*22667e32SJim Ingham {
45*22667e32SJim Ingham     {    5,    6 },
46*22667e32SJim Ingham     {   55,   66 }
47*22667e32SJim Ingham };
48*22667e32SJim Ingham 
4999451b44SJordan Rupprecht int
main(int argc,char const * argv[])5099451b44SJordan Rupprecht main (int argc, char const *argv[])
5199451b44SJordan Rupprecht {
5299451b44SJordan Rupprecht     const char *hello_world = "Hello, world!";
5399451b44SJordan Rupprecht     printf ("A::g_points[1].x = %i\n", A::g_points[1].x); // Set break point at this line.
54*22667e32SJim Ingham     printf ("AA::g_points[1].x = %i\n", AA::g_points[1].x);
5599451b44SJordan Rupprecht     printf ("::g_points[1].x = %i\n", g_points[1].x);
5699451b44SJordan Rupprecht     printf ("%s\n", hello_world);
5799451b44SJordan Rupprecht     return 0;
5899451b44SJordan Rupprecht }
59