xref: /llvm-project/clang/test/CXX/drs/cwg2149.cpp (revision 37f2928ce382603fdadd7bae87fa245ac65b7d4f)
11728a56dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes CXX98
21728a56dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
31728a56dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
41728a56dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
51728a56dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
61728a56dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
71728a56dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
81728a56dSVlad Serebrennikov 
91728a56dSVlad Serebrennikov #if __cplusplus == 199711L
101728a56dSVlad Serebrennikov #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
111728a56dSVlad Serebrennikov // cxx98-error@-1 {{variadic macros are a C99 feature}}
121728a56dSVlad Serebrennikov #endif
131728a56dSVlad Serebrennikov 
14*37f2928cSVlad Serebrennikov namespace cwg2149 { // cwg2149: 3.1
151728a56dSVlad Serebrennikov #if __cplusplus <= 201103L
161728a56dSVlad Serebrennikov struct X { int i, j, k; };
171728a56dSVlad Serebrennikov #else
181728a56dSVlad Serebrennikov struct X { int i, j, k = 42; };
191728a56dSVlad Serebrennikov #endif
201728a56dSVlad Serebrennikov 
211728a56dSVlad Serebrennikov template<int N>
221728a56dSVlad Serebrennikov void f1(const X(&)[N]); // #cwg2149-f1
231728a56dSVlad Serebrennikov 
241728a56dSVlad Serebrennikov template<int N>
251728a56dSVlad Serebrennikov void f2(const X(&)[N][2]); // #cwg2149-f2
261728a56dSVlad Serebrennikov 
f()271728a56dSVlad Serebrennikov void f() {
281728a56dSVlad Serebrennikov   X a[] = { 1, 2, 3, 4, 5, 6 };
291728a56dSVlad Serebrennikov   static_assert(sizeof(a) / sizeof(X) == 2, "");
301728a56dSVlad Serebrennikov   X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
311728a56dSVlad Serebrennikov   X c[][2] = { 1, 2, 3, 4, 5, 6 };
321728a56dSVlad Serebrennikov   static_assert(sizeof(c) / sizeof(X[2]) == 1, "");
331728a56dSVlad Serebrennikov 
341728a56dSVlad Serebrennikov   #if __cplusplus >= 201103L
351728a56dSVlad Serebrennikov   constexpr X ca[] = { 1, 2, 3, 4, 5, 6 };
361728a56dSVlad Serebrennikov   constexpr X cb[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
371728a56dSVlad Serebrennikov   static_assert(ca[0].i == cb[0].i, "");
381728a56dSVlad Serebrennikov   static_assert(ca[0].j == cb[0].j, "");
391728a56dSVlad Serebrennikov   static_assert(ca[0].k == cb[0].k, "");
401728a56dSVlad Serebrennikov   static_assert(ca[1].i == cb[1].i, "");
411728a56dSVlad Serebrennikov   static_assert(ca[1].j == cb[1].j, "");
421728a56dSVlad Serebrennikov   static_assert(ca[1].k == cb[1].k, "");
431728a56dSVlad Serebrennikov 
441728a56dSVlad Serebrennikov   f1({ 1, 2, 3, 4, 5, 6 });
451728a56dSVlad Serebrennikov   // since-cxx11-error@-1 {{no matching function for call to 'f1'}}
461728a56dSVlad Serebrennikov   //   since-cxx11-note@#cwg2149-f1 {{candidate function [with N = 6] not viable: no known conversion from 'int' to 'const X' for 1st argument}}
471728a56dSVlad Serebrennikov   f2({ 1, 2, 3, 4, 5, 6 });
481728a56dSVlad Serebrennikov   // since-cxx11-error@-1 {{no matching function for call to 'f2'}}
491728a56dSVlad Serebrennikov   //   since-cxx11-note@#cwg2149-f2 {{candidate function [with N = 6] not viable: no known conversion from 'int' to 'const X[2]' for 1st argument}}
501728a56dSVlad Serebrennikov   #endif
511728a56dSVlad Serebrennikov }
521728a56dSVlad Serebrennikov } // namespace cwg2149
531728a56dSVlad Serebrennikov 
541728a56dSVlad Serebrennikov // Constant evaluation is not powerful enough in 98 mode to check for equality
551728a56dSVlad Serebrennikov // via static_assert, even with constant folding enabled.
561728a56dSVlad Serebrennikov 
571728a56dSVlad Serebrennikov // CXX98:       VarDecl {{.+}} a 'X[2]'
581728a56dSVlad Serebrennikov // CXX98-NEXT:  `-InitListExpr {{.+}} 'X[2]'
591728a56dSVlad Serebrennikov // CXX98-NEXT:    |-InitListExpr {{.+}} 'X':'cwg2149::X'
601728a56dSVlad Serebrennikov // CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 1
611728a56dSVlad Serebrennikov // CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 2
621728a56dSVlad Serebrennikov // CXX98-NEXT:    | `-IntegerLiteral {{.+}} 'int' 3
631728a56dSVlad Serebrennikov // CXX98-NEXT:    `-InitListExpr {{.+}} 'X':'cwg2149::X'
641728a56dSVlad Serebrennikov // CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 4
651728a56dSVlad Serebrennikov // CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 5
661728a56dSVlad Serebrennikov // CXX98-NEXT:      `-IntegerLiteral {{.+}} 'int' 6
671728a56dSVlad Serebrennikov 
681728a56dSVlad Serebrennikov // CXX98:       VarDecl {{.+}} b 'X[2]'
691728a56dSVlad Serebrennikov // CXX98-NEXT:  `-InitListExpr {{.+}} 'X[2]'
701728a56dSVlad Serebrennikov // CXX98-NEXT:    |-InitListExpr {{.+}} 'X':'cwg2149::X'
711728a56dSVlad Serebrennikov // CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 1
721728a56dSVlad Serebrennikov // CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 2
731728a56dSVlad Serebrennikov // CXX98-NEXT:    | `-IntegerLiteral {{.+}} 'int' 3
741728a56dSVlad Serebrennikov // CXX98-NEXT:    `-InitListExpr {{.+}} 'X':'cwg2149::X'
751728a56dSVlad Serebrennikov // CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 4
761728a56dSVlad Serebrennikov // CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 5
771728a56dSVlad Serebrennikov // CXX98-NEXT:      `-IntegerLiteral {{.+}} 'int' 6
78