PR libstdc++/54924 - Warn for std::string constructor with wrong size
[official-gcc.git] / gcc / testsuite / g++.dg / ipa / pr63587-2.C
bloba15f17e7ca335a4433b1ae892d5a92c31b1df1de
1 // PR ipa/63587
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-O2" }
5 namespace boost {
6 class basic_cstring
8 public:
9   basic_cstring (char *);
11 template <typename> struct identity
14 struct make_identity;
15 struct function_buffer
18 template <typename FunctionObj> struct function_obj_invoker0
20   static int
21   invoke (function_buffer &)
22   {
23     FunctionObj f;
24     f ();
25   }
27 template <typename FunctionObj> struct get_function_obj_invoker0
29   typedef function_obj_invoker0<FunctionObj> type;
31 template <typename FunctionObj> struct apply
33   typedef typename get_function_obj_invoker0<FunctionObj>::type invoker_type;
35 struct basic_vtable0
37   typedef int (*invoker_type)(function_buffer &);
38   template <typename F> void assign_to (F, function_buffer);
39   invoker_type invoker;
41 class function0
43 public:
44   template <typename Functor> function0 (Functor)
45   {
46     typedef typename apply<Functor>::invoker_type invoker_type;
47     basic_vtable0 stored_vtable { invoker_type::invoke };
48     stored_vtable.assign_to (0, functor);
49   }
50   function_buffer functor;
52 class function : function0
54 public:
55   template <typename Functor> function (Functor f) : function0 (f) {}
57 class test_unit_generator
60 class test_case
62 public:
63   test_case (basic_cstring, basic_cstring, int, function);
65 struct auto_test_unit_registrar
67   auto_test_unit_registrar (test_unit_generator);
69 template <typename F> F unwrap (F, int);
70 struct for_each_impl
72   template <typename Iterator, typename LastIterator, typename TransformFunc,
73             typename F>
74   static void
75   execute (Iterator, LastIterator, TransformFunc, F f)
76   {
77     identity<char> __trans_tmp_1;
78     unwrap (f, 0)(__trans_tmp_1);
79   }
81 template <typename, typename, typename F>
82 void
83 for_each (F f)
85   for_each_impl::execute (0, 0, 0, f);
87 template <typename TestCaseTemplate> class test_case_template_invoker
89 public:
90   void operator()()
91   {
92     TestCaseTemplate::run (0);
93   }
95 template <typename Generator, typename TestCaseTemplate>
96 struct generate_test_case_4_type
98   generate_test_case_4_type (basic_cstring, basic_cstring, int, Generator G)
99     : m_test_case_name (0), m_test_case_file (0), m_holder (G)
100   {
101   }
102   template <typename TestType> void operator()(identity<TestType>)
103   {
104     test_case (0, 0, 0, test_case_template_invoker<TestCaseTemplate> ());
105   }
106   basic_cstring m_test_case_name;
107   basic_cstring m_test_case_file;
108   Generator m_holder;
110 template <typename TestCaseTemplate>
111 class template_test_case_gen : public test_unit_generator
113 public:
114   template_test_case_gen (basic_cstring, basic_cstring, int)
115   {
116     for_each<int, make_identity> (
117       generate_test_case_4_type<template_test_case_gen, TestCaseTemplate> (
118         0, 0, 0, *this));
119   }
121 class attribute_name
123   int m_id;
125 public:
126   attribute_name (char);
128 template <typename> struct term;
129 namespace exprns_ {
130 template <typename> struct expr;
132 using exprns_::expr;
133 template <typename T> struct Trans_NS_proto_terminal
135   typedef expr<term<T> > type;
137 namespace exprns_ {
138 template <typename Arg0> struct expr<term<Arg0> >
140   Arg0 child0;
143 template <typename Expr> struct actor
145   typename Trans_NS_proto_terminal<Expr>::type proto_expr_;
147 template <template <typename> class Actor = actor> struct terminal
149   typedef Actor<int> type;
151 namespace log {
152 struct to_log_fun
155 class value_extractor;
156 template <typename, typename = value_extractor, typename = void,
157           template <typename> class = actor>
158 class attribute_actor;
159 class attribute_terminal
161 public:
162   attribute_name m_name;
163   attribute_name
164   get_name ()
165   {
166     return m_name;
167   }
169 template <typename, typename, typename, template <typename> class ActorT>
170 class attribute_actor : ActorT<attribute_terminal>
172 public:
173   typedef int value_type;
174   attribute_name
175   get_name ()
176   {
177     return this->proto_expr_.child0.get_name ();
178   }
180 template <typename AttributeValueT>
181 attribute_actor<AttributeValueT> attr (attribute_name); // { dg-warning "used but never defined" }
182 terminal<>::type stream;
183 template <typename LeftT, typename ImplT> class attribute_output_terminal
185 public:
186   template <typename U>
187   attribute_output_terminal (LeftT, attribute_name, ImplT, U);
189 template <typename LeftT> struct make_output_expression
191   typedef attribute_output_terminal<LeftT, to_log_fun> type;
192   template <typename RightT>
193   static type
194   make (LeftT left, RightT &right)
195   {
196     type (left, right.get_name (), to_log_fun (), 0);
197   }
199 template <typename, typename RightT, typename = typename RightT::value_type>
200 struct make_output_actor;
201 template <template <typename> class ActorT, typename LeftExprT,
202           typename RightT, typename ValueT>
203 struct make_output_actor<ActorT<LeftExprT>, RightT, ValueT>
205   typedef make_output_expression<ActorT<LeftExprT> > make_expression;
206   typedef ActorT<typename make_expression::type> type;
207   static type
208   make (ActorT<LeftExprT> left, RightT &right)
209   {
210     type { make_expression::make (left, right) };
211   }
213 template <typename LeftExprT, typename T, typename FallbackPolicyT,
214           typename TagT>
215 typename make_output_actor<actor<LeftExprT>, attribute_actor<TagT> >::type
216 operator<<(actor<LeftExprT> left,
217            attribute_actor<T, FallbackPolicyT, TagT> right)
219   make_output_actor<actor<LeftExprT>, attribute_actor<T> >::make (left, right);
223 namespace logging = boost::log;
224 namespace expr = logging;
225 namespace {
226 class my_class;
228 template <typename> struct default_formatting
230   void test_method ();
232 struct default_formatting_invoker
234   static void
235   run (void *)
236   {
237     default_formatting<int> t;
238     t.test_method ();
239   }
241 boost::auto_test_unit_registrar default_formatting_registrar56 (
242   boost::template_test_case_gen<default_formatting_invoker> (0, 0, 0));
243 template <typename CharT>
244 void
245 default_formatting<CharT>::test_method ()
247   expr::stream << expr::attr<my_class> (0);
248   expr::stream << expr::attr<int> (0) << expr::attr<int> (0)
249                << expr::attr<int> (0);