OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [cp/] [method.c] - Blame information for rev 710

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 710 jeremybenn
/* Handle the hair of processing (but not expanding) inline functions.
2
   Also manage function and variable name overloading.
3
   Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4
   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
5
   Free Software Foundation, Inc.
6
   Contributed by Michael Tiemann (tiemann@cygnus.com)
7
 
8
This file is part of GCC.
9
 
10
GCC is free software; you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation; either version 3, or (at your option)
13
any later version.
14
 
15
GCC is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
GNU General Public License for more details.
19
 
20
You should have received a copy of the GNU General Public License
21
along with GCC; see the file COPYING3.  If not see
22
<http://www.gnu.org/licenses/>.  */
23
 
24
 
25
/* Handle method declarations.  */
26
#include "config.h"
27
#include "system.h"
28
#include "coretypes.h"
29
#include "tm.h"
30
#include "tree.h"
31
#include "cp-tree.h"
32
#include "output.h"
33
#include "flags.h"
34
#include "toplev.h"
35
#include "tm_p.h"
36
#include "target.h"
37
#include "common/common-target.h"
38
#include "tree-pass.h"
39
#include "diagnostic.h"
40
#include "cgraph.h"
41
#include "gimple.h"
42
 
43
/* Various flags to control the mangling process.  */
44
 
45
enum mangling_flags
46
{
47
  /* No flags.  */
48
  mf_none = 0,
49
  /* The thing we are presently mangling is part of a template type,
50
     rather than a fully instantiated type.  Therefore, we may see
51
     complex expressions where we would normally expect to see a
52
     simple integer constant.  */
53
  mf_maybe_uninstantiated = 1,
54
  /* When mangling a numeric value, use the form `_XX_' (instead of
55
     just `XX') if the value has more than one digit.  */
56
  mf_use_underscores_around_value = 2
57
};
58
 
59
typedef enum mangling_flags mangling_flags;
60
 
61
static void do_build_copy_assign (tree);
62
static void do_build_copy_constructor (tree);
63
static tree make_alias_for_thunk (tree);
64
 
65
/* Called once to initialize method.c.  */
66
 
67
void
68
init_method (void)
69
{
70
  init_mangle ();
71
}
72
 
73
/* Return a this or result adjusting thunk to FUNCTION.  THIS_ADJUSTING
74
   indicates whether it is a this or result adjusting thunk.
75
   FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
76
   (see thunk_adjust).  VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
77
   never is.  VIRTUAL_OFFSET is the /index/ into the vtable for this
78
   adjusting thunks, we scale it to a byte offset. For covariant
79
   thunks VIRTUAL_OFFSET is the virtual binfo.  You must post process
80
   the returned thunk with finish_thunk.  */
81
 
82
tree
83
make_thunk (tree function, bool this_adjusting,
84
            tree fixed_offset, tree virtual_offset)
85
{
86
  HOST_WIDE_INT d;
87
  tree thunk;
88
 
89
  gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
90
  /* We can have this thunks to covariant thunks, but not vice versa.  */
91
  gcc_assert (!DECL_THIS_THUNK_P (function));
92
  gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
93
 
94
  /* Scale the VIRTUAL_OFFSET to be in terms of bytes.  */
95
  if (this_adjusting && virtual_offset)
96
    virtual_offset
97
      = size_binop (MULT_EXPR,
98
                    virtual_offset,
99
                    convert (ssizetype,
100
                             TYPE_SIZE_UNIT (vtable_entry_type)));
101
 
102
  d = tree_low_cst (fixed_offset, 0);
103
 
104
  /* See if we already have the thunk in question.  For this_adjusting
105
     thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
106
     will be a BINFO.  */
107
  for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
108
    if (DECL_THIS_THUNK_P (thunk) == this_adjusting
109
        && THUNK_FIXED_OFFSET (thunk) == d
110
        && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
111
        && (!virtual_offset
112
            || (this_adjusting
113
                ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
114
                                      virtual_offset)
115
                : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
116
      return thunk;
117
 
118
  /* All thunks must be created before FUNCTION is actually emitted;
119
     the ABI requires that all thunks be emitted together with the
120
     function to which they transfer control.  */
121
  gcc_assert (!TREE_ASM_WRITTEN (function));
122
  /* Likewise, we can only be adding thunks to a function declared in
123
     the class currently being laid out.  */
124
  gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
125
              && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
126
 
127
  thunk = build_decl (DECL_SOURCE_LOCATION (function),
128
                      FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
129
  DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
130
  cxx_dup_lang_specific_decl (thunk);
131
  DECL_THUNKS (thunk) = NULL_TREE;
132
 
133
  DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
134
  TREE_READONLY (thunk) = TREE_READONLY (function);
135
  TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
136
  TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
137
  SET_DECL_THUNK_P (thunk, this_adjusting);
138
  THUNK_TARGET (thunk) = function;
139
  THUNK_FIXED_OFFSET (thunk) = d;
140
  THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
141
  THUNK_ALIAS (thunk) = NULL_TREE;
142
 
143
  DECL_INTERFACE_KNOWN (thunk) = 1;
144
  DECL_NOT_REALLY_EXTERN (thunk) = 1;
145
  DECL_COMDAT (thunk) = DECL_COMDAT (function);
146
  DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
147
  /* The thunk itself is not a constructor or destructor, even if
148
     the thing it is thunking to is.  */
149
  DECL_DESTRUCTOR_P (thunk) = 0;
150
  DECL_CONSTRUCTOR_P (thunk) = 0;
151
  DECL_EXTERNAL (thunk) = 1;
152
  DECL_ARTIFICIAL (thunk) = 1;
153
  /* The THUNK is not a pending inline, even if the FUNCTION is.  */
154
  DECL_PENDING_INLINE_P (thunk) = 0;
155
  DECL_DECLARED_INLINE_P (thunk) = 0;
156
  /* Nor is it a template instantiation.  */
157
  DECL_USE_TEMPLATE (thunk) = 0;
158
  DECL_TEMPLATE_INFO (thunk) = NULL;
159
 
160
  /* Add it to the list of thunks associated with FUNCTION.  */
161
  DECL_CHAIN (thunk) = DECL_THUNKS (function);
162
  DECL_THUNKS (function) = thunk;
163
 
164
  return thunk;
165
}
166
 
167
/* Finish THUNK, a thunk decl.  */
168
 
169
void
170
finish_thunk (tree thunk)
171
{
172
  tree function, name;
173
  tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
174
  tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
175
 
176
  gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
177
  if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
178
    virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
179
  function = THUNK_TARGET (thunk);
180
  name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
181
                       fixed_offset, virtual_offset);
182
 
183
  /* We can end up with declarations of (logically) different
184
     covariant thunks, that do identical adjustments.  The two thunks
185
     will be adjusting between within different hierarchies, which
186
     happen to have the same layout.  We must nullify one of them to
187
     refer to the other.  */
188
  if (DECL_RESULT_THUNK_P (thunk))
189
    {
190
      tree cov_probe;
191
 
192
      for (cov_probe = DECL_THUNKS (function);
193
           cov_probe; cov_probe = DECL_CHAIN (cov_probe))
194
        if (DECL_NAME (cov_probe) == name)
195
          {
196
            gcc_assert (!DECL_THUNKS (thunk));
197
            THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
198
                                   ? THUNK_ALIAS (cov_probe) : cov_probe);
199
            break;
200
          }
201
    }
202
 
203
  DECL_NAME (thunk) = name;
204
  SET_DECL_ASSEMBLER_NAME (thunk, name);
205
}
206
 
207
static GTY (()) int thunk_labelno;
208
 
209
/* Create a static alias to target.  */
210
 
211
tree
212
make_alias_for (tree target, tree newid)
213
{
214
  tree alias = build_decl (DECL_SOURCE_LOCATION (target),
215
                           TREE_CODE (target), newid, TREE_TYPE (target));
216
  DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
217
  cxx_dup_lang_specific_decl (alias);
218
  DECL_CONTEXT (alias) = NULL;
219
  TREE_READONLY (alias) = TREE_READONLY (target);
220
  TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
221
  TREE_PUBLIC (alias) = 0;
222
  DECL_INTERFACE_KNOWN (alias) = 1;
223
  if (DECL_LANG_SPECIFIC (alias))
224
    {
225
      DECL_NOT_REALLY_EXTERN (alias) = 1;
226
      DECL_USE_TEMPLATE (alias) = 0;
227
      DECL_TEMPLATE_INFO (alias) = NULL;
228
    }
229
  DECL_EXTERNAL (alias) = 0;
230
  DECL_ARTIFICIAL (alias) = 1;
231
  DECL_TEMPLATE_INSTANTIATED (alias) = 0;
232
  if (TREE_CODE (alias) == FUNCTION_DECL)
233
    {
234
      DECL_SAVED_FUNCTION_DATA (alias) = NULL;
235
      DECL_DESTRUCTOR_P (alias) = 0;
236
      DECL_CONSTRUCTOR_P (alias) = 0;
237
      DECL_PENDING_INLINE_P (alias) = 0;
238
      DECL_DECLARED_INLINE_P (alias) = 0;
239
      DECL_INITIAL (alias) = error_mark_node;
240
      DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
241
    }
242
  else
243
    TREE_STATIC (alias) = 1;
244
  TREE_ADDRESSABLE (alias) = 1;
245
  TREE_USED (alias) = 1;
246
  SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
247
  TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias)) = 1;
248
  return alias;
249
}
250
 
251
static tree
252
make_alias_for_thunk (tree function)
253
{
254
  tree alias;
255
  char buf[256];
256
 
257
  targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
258
  thunk_labelno++;
259
 
260
  alias = make_alias_for (function, get_identifier (buf));
261
 
262
  if (!flag_syntax_only)
263
    {
264
      struct cgraph_node *funcn, *aliasn;
265
      funcn = cgraph_get_node (function);
266
      gcc_checking_assert (funcn);
267
      aliasn = cgraph_same_body_alias (funcn, alias, function);
268
      DECL_ASSEMBLER_NAME (function);
269
      gcc_assert (aliasn != NULL);
270
    }
271
 
272
  return alias;
273
}
274
 
275
/* Emit the definition of a C++ multiple inheritance or covariant
276
   return vtable thunk.  If EMIT_P is nonzero, the thunk is emitted
277
   immediately.  */
278
 
279
void
280
use_thunk (tree thunk_fndecl, bool emit_p)
281
{
282
  tree a, t, function, alias;
283
  tree virtual_offset;
284
  HOST_WIDE_INT fixed_offset, virtual_value;
285
  bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
286
  struct cgraph_node *funcn, *thunk_node;
287
 
288
  /* We should have called finish_thunk to give it a name.  */
289
  gcc_assert (DECL_NAME (thunk_fndecl));
290
 
291
  /* We should never be using an alias, always refer to the
292
     aliased thunk.  */
293
  gcc_assert (!THUNK_ALIAS (thunk_fndecl));
294
 
295
  if (TREE_ASM_WRITTEN (thunk_fndecl))
296
    return;
297
 
298
  function = THUNK_TARGET (thunk_fndecl);
299
  if (DECL_RESULT (thunk_fndecl))
300
    /* We already turned this thunk into an ordinary function.
301
       There's no need to process this thunk again.  */
302
    return;
303
 
304
  if (DECL_THUNK_P (function))
305
    /* The target is itself a thunk, process it now.  */
306
    use_thunk (function, emit_p);
307
 
308
  /* Thunks are always addressable; they only appear in vtables.  */
309
  TREE_ADDRESSABLE (thunk_fndecl) = 1;
310
 
311
  /* Figure out what function is being thunked to.  It's referenced in
312
     this translation unit.  */
313
  TREE_ADDRESSABLE (function) = 1;
314
  mark_used (function);
315
  if (!emit_p)
316
    return;
317
 
318
  if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
319
   alias = make_alias_for_thunk (function);
320
  else
321
   alias = function;
322
 
323
  fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
324
  virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
325
 
326
  if (virtual_offset)
327
    {
328
      if (!this_adjusting)
329
        virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
330
      virtual_value = tree_low_cst (virtual_offset, /*pos=*/0);
331
      gcc_assert (virtual_value);
332
    }
333
  else
334
    virtual_value = 0;
335
 
336
  /* And, if we need to emit the thunk, it's used.  */
337
  mark_used (thunk_fndecl);
338
  /* This thunk is actually defined.  */
339
  DECL_EXTERNAL (thunk_fndecl) = 0;
340
  /* The linkage of the function may have changed.  FIXME in linkage
341
     rewrite.  */
342
  gcc_assert (DECL_INTERFACE_KNOWN (function));
343
  TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
344
  DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
345
  DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
346
    = DECL_VISIBILITY_SPECIFIED (function);
347
  DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
348
  DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
349
 
350
  if (flag_syntax_only)
351
    {
352
      TREE_ASM_WRITTEN (thunk_fndecl) = 1;
353
      return;
354
    }
355
 
356
  push_to_top_level ();
357
 
358
  if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
359
      && targetm_common.have_named_sections)
360
    {
361
      resolve_unique_section (function, 0, flag_function_sections);
362
 
363
      if (DECL_SECTION_NAME (function) != NULL && DECL_ONE_ONLY (function))
364
        {
365
          resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
366
 
367
          /* Output the thunk into the same section as function.  */
368
          DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function);
369
        }
370
    }
371
 
372
  /* Set up cloned argument trees for the thunk.  */
373
  t = NULL_TREE;
374
  for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
375
    {
376
      tree x = copy_node (a);
377
      DECL_CHAIN (x) = t;
378
      DECL_CONTEXT (x) = thunk_fndecl;
379
      SET_DECL_RTL (x, NULL);
380
      DECL_HAS_VALUE_EXPR_P (x) = 0;
381
      TREE_ADDRESSABLE (x) = 0;
382
      t = x;
383
    }
384
  a = nreverse (t);
385
  DECL_ARGUMENTS (thunk_fndecl) = a;
386
  TREE_ASM_WRITTEN (thunk_fndecl) = 1;
387
  funcn = cgraph_get_node (function);
388
  gcc_checking_assert (funcn);
389
  thunk_node = cgraph_add_thunk (funcn, thunk_fndecl, function,
390
                                 this_adjusting, fixed_offset, virtual_value,
391
                                 virtual_offset, alias);
392
  if (DECL_ONE_ONLY (function))
393
    cgraph_add_to_same_comdat_group (thunk_node, funcn);
394
 
395
  if (!this_adjusting
396
      || !targetm.asm_out.can_output_mi_thunk (thunk_fndecl, fixed_offset,
397
                                               virtual_value, alias))
398
    {
399
      /* If this is a covariant thunk, or we don't have the necessary
400
         code for efficient thunks, generate a thunk function that
401
         just makes a call to the real function.  Unfortunately, this
402
         doesn't work for varargs.  */
403
 
404
      if (varargs_function_p (function))
405
        error ("generic thunk code fails for method %q#D which uses %<...%>",
406
               function);
407
    }
408
 
409
  pop_from_top_level ();
410
}
411
 
412
/* Code for synthesizing methods which have default semantics defined.  */
413
 
414
/* True iff CTYPE has a trivial SFK.  */
415
 
416
static bool
417
type_has_trivial_fn (tree ctype, special_function_kind sfk)
418
{
419
  switch (sfk)
420
    {
421
    case sfk_constructor:
422
      return !TYPE_HAS_COMPLEX_DFLT (ctype);
423
    case sfk_copy_constructor:
424
      return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
425
    case sfk_move_constructor:
426
      return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
427
    case sfk_copy_assignment:
428
      return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
429
    case sfk_move_assignment:
430
      return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
431
    case sfk_destructor:
432
      return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
433
    default:
434
      gcc_unreachable ();
435
    }
436
}
437
 
438
/* Note that CTYPE has a non-trivial SFK even though we previously thought
439
   it was trivial.  */
440
 
441
static void
442
type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
443
{
444
  switch (sfk)
445
    {
446
    case sfk_constructor:
447
      TYPE_HAS_COMPLEX_DFLT (ctype) = true;
448
      return;
449
    case sfk_copy_constructor:
450
      TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
451
      return;
452
    case sfk_move_constructor:
453
      TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
454
      return;
455
    case sfk_copy_assignment:
456
      TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
457
      return;
458
    case sfk_move_assignment:
459
      TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
460
      return;
461
    case sfk_destructor:
462
      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
463
      return;
464
    default:
465
      gcc_unreachable ();
466
    }
467
}
468
 
469
/* True iff FN is a trivial defaulted member function ([cd]tor, op=).  */
470
 
471
bool
472
trivial_fn_p (tree fn)
473
{
474
  if (!DECL_DEFAULTED_FN (fn))
475
    return false;
476
 
477
  /* If fn is a clone, get the primary variant.  */
478
  fn = DECL_ORIGIN (fn);
479
  return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
480
}
481
 
482
/* Generate code for default X(X&) or X(X&&) constructor.  */
483
 
484
static void
485
do_build_copy_constructor (tree fndecl)
486
{
487
  tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
488
  bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
489
  bool trivial = trivial_fn_p (fndecl);
490
 
491
  parm = convert_from_reference (parm);
492
 
493
  if (trivial
494
      && is_empty_class (current_class_type))
495
    /* Don't copy the padding byte; it might not have been allocated
496
       if *this is a base subobject.  */;
497
  else if (trivial)
498
    {
499
      tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
500
      finish_expr_stmt (t);
501
    }
502
  else
503
    {
504
      tree fields = TYPE_FIELDS (current_class_type);
505
      tree member_init_list = NULL_TREE;
506
      int cvquals = cp_type_quals (TREE_TYPE (parm));
507
      int i;
508
      tree binfo, base_binfo;
509
      tree init;
510
      VEC(tree,gc) *vbases;
511
 
512
      /* Initialize all the base-classes with the parameter converted
513
         to their type so that we get their copy constructor and not
514
         another constructor that takes current_class_type.  We must
515
         deal with the binfo's directly as a direct base might be
516
         inaccessible due to ambiguity.  */
517
      for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
518
           VEC_iterate (tree, vbases, i, binfo); i++)
519
        {
520
          init = build_base_path (PLUS_EXPR, parm, binfo, 1,
521
                                  tf_warning_or_error);
522
          if (move_p)
523
            init = move (init);
524
          member_init_list
525
            = tree_cons (binfo,
526
                         build_tree_list (NULL_TREE, init),
527
                         member_init_list);
528
        }
529
 
530
      for (binfo = TYPE_BINFO (current_class_type), i = 0;
531
           BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
532
        {
533
          if (BINFO_VIRTUAL_P (base_binfo))
534
            continue;
535
 
536
          init = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
537
                                  tf_warning_or_error);
538
          if (move_p)
539
            init = move (init);
540
          member_init_list
541
            = tree_cons (base_binfo,
542
                         build_tree_list (NULL_TREE, init),
543
                         member_init_list);
544
        }
545
 
546
      for (; fields; fields = DECL_CHAIN (fields))
547
        {
548
          tree field = fields;
549
          tree expr_type;
550
 
551
          if (TREE_CODE (field) != FIELD_DECL)
552
            continue;
553
 
554
          expr_type = TREE_TYPE (field);
555
          if (DECL_NAME (field))
556
            {
557
              if (VFIELD_NAME_P (DECL_NAME (field)))
558
                continue;
559
            }
560
          else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
561
            /* Just use the field; anonymous types can't have
562
               nontrivial copy ctors or assignment ops or this
563
               function would be deleted.  */;
564
          else
565
            continue;
566
 
567
          /* Compute the type of "init->field".  If the copy-constructor
568
             parameter is, for example, "const S&", and the type of
569
             the field is "T", then the type will usually be "const
570
             T".  (There are no cv-qualified variants of reference
571
             types.)  */
572
          if (TREE_CODE (expr_type) != REFERENCE_TYPE)
573
            {
574
              int quals = cvquals;
575
 
576
              if (DECL_MUTABLE_P (field))
577
                quals &= ~TYPE_QUAL_CONST;
578
              quals |= cp_type_quals (expr_type);
579
              expr_type = cp_build_qualified_type (expr_type, quals);
580
            }
581
 
582
          init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
583
          if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE)
584
            init = move (init);
585
          init = build_tree_list (NULL_TREE, init);
586
 
587
          member_init_list = tree_cons (field, init, member_init_list);
588
        }
589
      finish_mem_initializers (member_init_list);
590
    }
591
}
592
 
593
static void
594
do_build_copy_assign (tree fndecl)
595
{
596
  tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
597
  tree compound_stmt;
598
  bool move_p = move_fn_p (fndecl);
599
  bool trivial = trivial_fn_p (fndecl);
600
  int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
601
 
602
  compound_stmt = begin_compound_stmt (0);
603
  parm = convert_from_reference (parm);
604
 
605
  if (trivial
606
      && is_empty_class (current_class_type))
607
    /* Don't copy the padding byte; it might not have been allocated
608
       if *this is a base subobject.  */;
609
  else if (trivial)
610
    {
611
      tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
612
      finish_expr_stmt (t);
613
    }
614
  else
615
    {
616
      tree fields;
617
      int cvquals = cp_type_quals (TREE_TYPE (parm));
618
      int i;
619
      tree binfo, base_binfo;
620
 
621
      /* Assign to each of the direct base classes.  */
622
      for (binfo = TYPE_BINFO (current_class_type), i = 0;
623
           BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
624
        {
625
          tree converted_parm;
626
          VEC(tree,gc) *parmvec;
627
 
628
          /* We must convert PARM directly to the base class
629
             explicitly since the base class may be ambiguous.  */
630
          converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
631
                                            tf_warning_or_error);
632
          if (move_p)
633
            converted_parm = move (converted_parm);
634
          /* Call the base class assignment operator.  */
635
          parmvec = make_tree_vector_single (converted_parm);
636
          finish_expr_stmt
637
            (build_special_member_call (current_class_ref,
638
                                        ansi_assopname (NOP_EXPR),
639
                                        &parmvec,
640
                                        base_binfo,
641
                                        flags,
642
                                        tf_warning_or_error));
643
          release_tree_vector (parmvec);
644
        }
645
 
646
      /* Assign to each of the non-static data members.  */
647
      for (fields = TYPE_FIELDS (current_class_type);
648
           fields;
649
           fields = DECL_CHAIN (fields))
650
        {
651
          tree comp = current_class_ref;
652
          tree init = parm;
653
          tree field = fields;
654
          tree expr_type;
655
          int quals;
656
 
657
          if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
658
            continue;
659
 
660
          expr_type = TREE_TYPE (field);
661
 
662
          if (CP_TYPE_CONST_P (expr_type))
663
            {
664
              error ("non-static const member %q#D, can%'t use default "
665
                     "assignment operator", field);
666
              continue;
667
            }
668
          else if (TREE_CODE (expr_type) == REFERENCE_TYPE)
669
            {
670
              error ("non-static reference member %q#D, can%'t use "
671
                     "default assignment operator", field);
672
              continue;
673
            }
674
 
675
          if (DECL_NAME (field))
676
            {
677
              if (VFIELD_NAME_P (DECL_NAME (field)))
678
                continue;
679
            }
680
          else if (ANON_AGGR_TYPE_P (expr_type)
681
                   && TYPE_FIELDS (expr_type) != NULL_TREE)
682
            /* Just use the field; anonymous types can't have
683
               nontrivial copy ctors or assignment ops or this
684
               function would be deleted.  */;
685
          else
686
            continue;
687
 
688
          comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
689
 
690
          /* Compute the type of init->field  */
691
          quals = cvquals;
692
          if (DECL_MUTABLE_P (field))
693
            quals &= ~TYPE_QUAL_CONST;
694
          expr_type = cp_build_qualified_type (expr_type, quals);
695
 
696
          init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
697
          if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE)
698
            init = move (init);
699
 
700
          if (DECL_NAME (field))
701
            init = cp_build_modify_expr (comp, NOP_EXPR, init,
702
                                         tf_warning_or_error);
703
          else
704
            init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
705
          finish_expr_stmt (init);
706
        }
707
    }
708
  finish_return_stmt (current_class_ref);
709
  finish_compound_stmt (compound_stmt);
710
}
711
 
712
/* Synthesize FNDECL, a non-static member function.   */
713
 
714
void
715
synthesize_method (tree fndecl)
716
{
717
  bool nested = (current_function_decl != NULL_TREE);
718
  tree context = decl_function_context (fndecl);
719
  bool need_body = true;
720
  tree stmt;
721
  location_t save_input_location = input_location;
722
  int error_count = errorcount;
723
  int warning_count = warningcount;
724
 
725
  /* Reset the source location, we might have been previously
726
     deferred, and thus have saved where we were first needed.  */
727
  DECL_SOURCE_LOCATION (fndecl)
728
    = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
729
 
730
  /* If we've been asked to synthesize a clone, just synthesize the
731
     cloned function instead.  Doing so will automatically fill in the
732
     body for the clone.  */
733
  if (DECL_CLONED_FUNCTION_P (fndecl))
734
    fndecl = DECL_CLONED_FUNCTION (fndecl);
735
 
736
  /* We may be in the middle of deferred access check.  Disable
737
     it now.  */
738
  push_deferring_access_checks (dk_no_deferred);
739
 
740
  if (! context)
741
    push_to_top_level ();
742
  else if (nested)
743
    push_function_context ();
744
 
745
  input_location = DECL_SOURCE_LOCATION (fndecl);
746
 
747
  start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
748
  stmt = begin_function_body ();
749
 
750
  if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
751
    {
752
      do_build_copy_assign (fndecl);
753
      need_body = false;
754
    }
755
  else if (DECL_CONSTRUCTOR_P (fndecl))
756
    {
757
      tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
758
      if (arg_chain != void_list_node)
759
        do_build_copy_constructor (fndecl);
760
      else
761
        finish_mem_initializers (NULL_TREE);
762
    }
763
 
764
  /* If we haven't yet generated the body of the function, just
765
     generate an empty compound statement.  */
766
  if (need_body)
767
    {
768
      tree compound_stmt;
769
      compound_stmt = begin_compound_stmt (BCS_FN_BODY);
770
      finish_compound_stmt (compound_stmt);
771
    }
772
 
773
  finish_function_body (stmt);
774
  expand_or_defer_fn (finish_function (0));
775
 
776
  input_location = save_input_location;
777
 
778
  if (! context)
779
    pop_from_top_level ();
780
  else if (nested)
781
    pop_function_context ();
782
 
783
  pop_deferring_access_checks ();
784
 
785
  if (error_count != errorcount || warning_count != warningcount)
786
    inform (input_location, "synthesized method %qD first required here ",
787
            fndecl);
788
}
789
 
790
/* Build a reference to type TYPE with cv-quals QUALS, which is an
791
   rvalue if RVALUE is true.  */
792
 
793
static tree
794
build_stub_type (tree type, int quals, bool rvalue)
795
{
796
  tree argtype = cp_build_qualified_type (type, quals);
797
  return cp_build_reference_type (argtype, rvalue);
798
}
799
 
800
/* Build a dummy glvalue from dereferencing a dummy reference of type
801
   REFTYPE.  */
802
 
803
static tree
804
build_stub_object (tree reftype)
805
{
806
  tree stub = build1 (NOP_EXPR, reftype, integer_one_node);
807
  return convert_from_reference (stub);
808
}
809
 
810
/* Determine which function will be called when looking up NAME in TYPE,
811
   called with a single ARGTYPE argument, or no argument if ARGTYPE is
812
   null.  FLAGS and COMPLAIN are as for build_new_method_call.
813
 
814
   Returns a FUNCTION_DECL if all is well.
815
   Returns NULL_TREE if overload resolution failed.
816
   Returns error_mark_node if the chosen function cannot be called.  */
817
 
818
static tree
819
locate_fn_flags (tree type, tree name, tree argtype, int flags,
820
                 tsubst_flags_t complain)
821
{
822
  tree ob, fn, fns, binfo, rval;
823
  VEC(tree,gc) *args;
824
 
825
  if (TYPE_P (type))
826
    binfo = TYPE_BINFO (type);
827
  else
828
    {
829
      binfo = type;
830
      type = BINFO_TYPE (binfo);
831
    }
832
 
833
  ob = build_stub_object (cp_build_reference_type (type, false));
834
  args = make_tree_vector ();
835
  if (argtype)
836
    {
837
      tree arg = build_stub_object (argtype);
838
      VEC_quick_push (tree, args, arg);
839
    }
840
 
841
  fns = lookup_fnfields (binfo, name, 0);
842
  rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
843
 
844
  release_tree_vector (args);
845
  if (fn && rval == error_mark_node)
846
    return rval;
847
  else
848
    return fn;
849
}
850
 
851
/* Locate the dtor of TYPE.  */
852
 
853
tree
854
get_dtor (tree type, tsubst_flags_t complain)
855
{
856
  tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
857
                             LOOKUP_NORMAL, complain);
858
  if (fn == error_mark_node)
859
    return NULL_TREE;
860
  return fn;
861
}
862
 
863
/* Locate the default ctor of TYPE.  */
864
 
865
tree
866
locate_ctor (tree type)
867
{
868
  tree fn;
869
 
870
  push_deferring_access_checks (dk_no_check);
871
  fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
872
                        LOOKUP_SPECULATIVE, tf_none);
873
  pop_deferring_access_checks ();
874
  if (fn == error_mark_node)
875
    return NULL_TREE;
876
  return fn;
877
}
878
 
879
/* Likewise, but give any appropriate errors.  */
880
 
881
tree
882
get_default_ctor (tree type)
883
{
884
  tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
885
                             LOOKUP_NORMAL, tf_warning_or_error);
886
  if (fn == error_mark_node)
887
    return NULL_TREE;
888
  return fn;
889
}
890
 
891
/* Locate the copy ctor of TYPE.  */
892
 
893
tree
894
get_copy_ctor (tree type, tsubst_flags_t complain)
895
{
896
  int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
897
               ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
898
  tree argtype = build_stub_type (type, quals, false);
899
  tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
900
                             LOOKUP_NORMAL, complain);
901
  if (fn == error_mark_node)
902
    return NULL_TREE;
903
  return fn;
904
}
905
 
906
/* Locate the copy assignment operator of TYPE.  */
907
 
908
tree
909
get_copy_assign (tree type)
910
{
911
  int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
912
               ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
913
  tree argtype = build_stub_type (type, quals, false);
914
  tree fn = locate_fn_flags (type, ansi_assopname (NOP_EXPR), argtype,
915
                             LOOKUP_NORMAL, tf_warning_or_error);
916
  if (fn == error_mark_node)
917
    return NULL_TREE;
918
  return fn;
919
}
920
 
921
/* Subroutine of synthesized_method_walk.  Update SPEC_P, TRIVIAL_P and
922
   DELETED_P or give an error message MSG with argument ARG.  */
923
 
924
static void
925
process_subob_fn (tree fn, bool move_p, tree *spec_p, bool *trivial_p,
926
                  bool *deleted_p, bool *constexpr_p,
927
                  const char *msg, tree arg)
928
{
929
  if (!fn || fn == error_mark_node)
930
    goto bad;
931
 
932
  if (spec_p)
933
    {
934
      tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
935
      *spec_p = merge_exception_specifiers (*spec_p, raises, fn);
936
    }
937
 
938
  if (!trivial_fn_p (fn))
939
    {
940
      if (trivial_p)
941
        *trivial_p = false;
942
      if (TREE_CODE (arg) == FIELD_DECL
943
          && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
944
        {
945
          if (deleted_p)
946
            *deleted_p = true;
947
          if (msg)
948
            error ("union member %q+D with non-trivial %qD", arg, fn);
949
        }
950
    }
951
 
952
  if (move_p && !move_fn_p (fn) && !trivial_fn_p (fn))
953
    {
954
      if (msg)
955
        error (msg, arg);
956
      goto bad;
957
    }
958
 
959
  if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
960
    {
961
      *constexpr_p = false;
962
      if (msg)
963
        {
964
          inform (0, "defaulted constructor calls non-constexpr "
965
                  "%q+D", fn);
966
          explain_invalid_constexpr_fn (fn);
967
        }
968
    }
969
 
970
  return;
971
 
972
 bad:
973
  if (deleted_p)
974
    *deleted_p = true;
975
}
976
 
977
/* Subroutine of synthesized_method_walk to allow recursion into anonymous
978
   aggregates.  */
979
 
980
static void
981
walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
982
                   int quals, bool copy_arg_p, bool move_p,
983
                   bool assign_p, tree *spec_p, bool *trivial_p,
984
                   bool *deleted_p, bool *constexpr_p, const char *msg,
985
                   int flags, tsubst_flags_t complain)
986
{
987
  tree field;
988
  for (field = fields; field; field = DECL_CHAIN (field))
989
    {
990
      tree mem_type, argtype, rval;
991
 
992
      if (TREE_CODE (field) != FIELD_DECL
993
          || DECL_ARTIFICIAL (field))
994
        continue;
995
 
996
      mem_type = strip_array_types (TREE_TYPE (field));
997
      if (assign_p)
998
        {
999
          bool bad = true;
1000
          if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
1001
            {
1002
              if (msg)
1003
                error ("non-static const member %q#D, can%'t use default "
1004
                       "assignment operator", field);
1005
            }
1006
          else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1007
            {
1008
              if (msg)
1009
                error ("non-static reference member %q#D, can%'t use "
1010
                       "default assignment operator", field);
1011
            }
1012
          else
1013
            bad = false;
1014
 
1015
          if (bad && deleted_p)
1016
            *deleted_p = true;
1017
        }
1018
      else if (sfk == sfk_constructor)
1019
        {
1020
          bool bad;
1021
 
1022
          if (DECL_INITIAL (field))
1023
            {
1024
              if (msg && DECL_INITIAL (field) == error_mark_node)
1025
                inform (0, "initializer for %q+#D is invalid", field);
1026
              if (trivial_p)
1027
                *trivial_p = false;
1028
#if 0
1029
              /* Core 1351: If the field has an NSDMI that could throw, the
1030
                 default constructor is noexcept(false).  FIXME this is
1031
                 broken by deferred parsing and 1360 saying we can't lazily
1032
                 declare a non-trivial default constructor.  Also this
1033
                 needs to do deferred instantiation.  Disable until the
1034
                 conflict between 1351 and 1360 is resolved.  */
1035
              if (spec_p && !expr_noexcept_p (DECL_INITIAL (field), complain))
1036
                *spec_p = noexcept_false_spec;
1037
#endif
1038
 
1039
              /* Don't do the normal processing.  */
1040
              continue;
1041
            }
1042
 
1043
          bad = false;
1044
          if (CP_TYPE_CONST_P (mem_type)
1045
              && default_init_uninitialized_part (mem_type))
1046
            {
1047
              if (msg)
1048
                error ("uninitialized non-static const member %q#D",
1049
                       field);
1050
              bad = true;
1051
            }
1052
          else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1053
            {
1054
              if (msg)
1055
                error ("uninitialized non-static reference member %q#D",
1056
                       field);
1057
              bad = true;
1058
            }
1059
 
1060
          if (bad && deleted_p)
1061
            *deleted_p = true;
1062
 
1063
          /* For an implicitly-defined default constructor to be constexpr,
1064
             every member must have a user-provided default constructor or
1065
             an explicit initializer.  */
1066
          if (constexpr_p && !CLASS_TYPE_P (mem_type)
1067
              && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
1068
            {
1069
              *constexpr_p = false;
1070
              if (msg)
1071
                inform (0, "defaulted default constructor does not "
1072
                        "initialize %q+#D", field);
1073
            }
1074
        }
1075
 
1076
      if (!CLASS_TYPE_P (mem_type))
1077
        continue;
1078
 
1079
      if (ANON_AGGR_TYPE_P (mem_type))
1080
        {
1081
          walk_field_subobs (TYPE_FIELDS (mem_type), fnname, sfk, quals,
1082
                             copy_arg_p, move_p, assign_p, spec_p, trivial_p,
1083
                             deleted_p, constexpr_p, msg, flags, complain);
1084
          continue;
1085
        }
1086
 
1087
      if (copy_arg_p)
1088
        {
1089
          int mem_quals = cp_type_quals (mem_type) | quals;
1090
          if (DECL_MUTABLE_P (field))
1091
            mem_quals &= ~TYPE_QUAL_CONST;
1092
          argtype = build_stub_type (mem_type, mem_quals, move_p);
1093
        }
1094
      else
1095
        argtype = NULL_TREE;
1096
 
1097
      rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
1098
 
1099
      process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
1100
                        constexpr_p, msg, field);
1101
    }
1102
}
1103
 
1104
/* The caller wants to generate an implicit declaration of SFK for CTYPE
1105
   which is const if relevant and CONST_P is set.  If spec_p, trivial_p and
1106
   deleted_p are non-null, set their referent appropriately.  If diag is
1107
   true, we're either being called from maybe_explain_implicit_delete to
1108
   give errors, or if constexpr_p is non-null, from
1109
   explain_invalid_constexpr_fn.  */
1110
 
1111
static void
1112
synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
1113
                         tree *spec_p, bool *trivial_p, bool *deleted_p,
1114
                         bool *constexpr_p, bool diag)
1115
{
1116
  tree binfo, base_binfo, scope, fnname, rval, argtype;
1117
  bool move_p, copy_arg_p, assign_p, expected_trivial, check_vdtor;
1118
  VEC(tree,gc) *vbases;
1119
  int i, quals, flags;
1120
  tsubst_flags_t complain;
1121
  const char *msg;
1122
  bool ctor_p;
1123
 
1124
  if (spec_p)
1125
    *spec_p = (cxx_dialect >= cxx0x ? noexcept_true_spec : empty_except_spec);
1126
 
1127
  if (deleted_p)
1128
    {
1129
      /* "The closure type associated with a lambda-expression has a deleted
1130
         default constructor and a deleted copy assignment operator."
1131
         This is diagnosed in maybe_explain_implicit_delete.  */
1132
      if (LAMBDA_TYPE_P (ctype)
1133
          && (sfk == sfk_constructor
1134
              || sfk == sfk_copy_assignment))
1135
        {
1136
          *deleted_p = true;
1137
          return;
1138
        }
1139
 
1140
      *deleted_p = false;
1141
    }
1142
 
1143
  ctor_p = false;
1144
  assign_p = false;
1145
  check_vdtor = false;
1146
  switch (sfk)
1147
    {
1148
    case sfk_move_assignment:
1149
    case sfk_copy_assignment:
1150
      assign_p = true;
1151
      fnname = ansi_assopname (NOP_EXPR);
1152
      break;
1153
 
1154
    case sfk_destructor:
1155
      check_vdtor = true;
1156
      /* The synthesized method will call base dtors, but check complete
1157
         here to avoid having to deal with VTT.  */
1158
      fnname = complete_dtor_identifier;
1159
      break;
1160
 
1161
    case sfk_constructor:
1162
    case sfk_move_constructor:
1163
    case sfk_copy_constructor:
1164
      ctor_p = true;
1165
      fnname = complete_ctor_identifier;
1166
      break;
1167
 
1168
    default:
1169
      gcc_unreachable ();
1170
    }
1171
 
1172
  /* If that user-written default constructor would satisfy the
1173
     requirements of a constexpr constructor (7.1.5), the
1174
     implicitly-defined default constructor is constexpr.  */
1175
  if (constexpr_p)
1176
    *constexpr_p = ctor_p;
1177
 
1178
  move_p = false;
1179
  switch (sfk)
1180
    {
1181
    case sfk_constructor:
1182
    case sfk_destructor:
1183
      copy_arg_p = false;
1184
      break;
1185
 
1186
    case sfk_move_constructor:
1187
    case sfk_move_assignment:
1188
      move_p = true;
1189
    case sfk_copy_constructor:
1190
    case sfk_copy_assignment:
1191
      copy_arg_p = true;
1192
      break;
1193
 
1194
    default:
1195
      gcc_unreachable ();
1196
    }
1197
 
1198
  expected_trivial = type_has_trivial_fn (ctype, sfk);
1199
  if (trivial_p)
1200
    *trivial_p = expected_trivial;
1201
 
1202
  /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
1203
     class versions and other properties of the type.  But a subobject
1204
     class can be trivially copyable and yet have overload resolution
1205
     choose a template constructor for initialization, depending on
1206
     rvalueness and cv-quals.  So we can't exit early for copy/move
1207
     methods in C++0x.  The same considerations apply in C++98/03, but
1208
     there the definition of triviality does not consider overload
1209
     resolution, so a constructor can be trivial even if it would otherwise
1210
     call a non-trivial constructor.  */
1211
  if (expected_trivial
1212
      && (!copy_arg_p || cxx_dialect < cxx0x))
1213
    {
1214
      if (constexpr_p && sfk == sfk_constructor)
1215
        {
1216
          bool cx = trivial_default_constructor_is_constexpr (ctype);
1217
          *constexpr_p = cx;
1218
          if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
1219
            /* A trivial constructor doesn't have any NSDMI.  */
1220
            inform (input_location, "defaulted default constructor does "
1221
                    "not initialize any non-static data member");
1222
        }
1223
      if (!diag)
1224
        return;
1225
    }
1226
 
1227
  ++cp_unevaluated_operand;
1228
  ++c_inhibit_evaluation_warnings;
1229
 
1230
  scope = push_scope (ctype);
1231
 
1232
  if (diag)
1233
    {
1234
      flags = LOOKUP_NORMAL|LOOKUP_SPECULATIVE|LOOKUP_DEFAULTED;
1235
      complain = tf_warning_or_error;
1236
    }
1237
  else
1238
    {
1239
      flags = LOOKUP_PROTECT|LOOKUP_SPECULATIVE|LOOKUP_DEFAULTED;
1240
      complain = tf_none;
1241
    }
1242
 
1243
  if (const_p)
1244
    quals = TYPE_QUAL_CONST;
1245
  else
1246
    quals = TYPE_UNQUALIFIED;
1247
  argtype = NULL_TREE;
1248
 
1249
  if (!diag)
1250
    msg = NULL;
1251
  else if (assign_p)
1252
    msg = ("base %qT does not have a move assignment operator or trivial "
1253
           "copy assignment operator");
1254
  else
1255
    msg = ("base %qT does not have a move constructor or trivial "
1256
           "copy constructor");
1257
 
1258
  for (binfo = TYPE_BINFO (ctype), i = 0;
1259
       BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
1260
    {
1261
      tree basetype = BINFO_TYPE (base_binfo);
1262
      if (copy_arg_p)
1263
        argtype = build_stub_type (basetype, quals, move_p);
1264
      rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1265
 
1266
      process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
1267
                        constexpr_p, msg, basetype);
1268
      if (ctor_p && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype))
1269
        {
1270
          /* In a constructor we also need to check the subobject
1271
             destructors for cleanup of partially constructed objects.  */
1272
          rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
1273
                                  NULL_TREE, flags, complain);
1274
          /* Note that we don't pass down trivial_p; the subobject
1275
             destructors don't affect triviality of the constructor.  */
1276
          process_subob_fn (rval, false, spec_p, NULL,
1277
                            deleted_p, NULL, NULL,
1278
                            basetype);
1279
        }
1280
 
1281
      if (check_vdtor && type_has_virtual_destructor (basetype))
1282
        {
1283
          rval = locate_fn_flags (ctype, ansi_opname (DELETE_EXPR),
1284
                                  ptr_type_node, flags, complain);
1285
          /* Unlike for base ctor/op=/dtor, for operator delete it's fine
1286
             to have a null rval (no class-specific op delete).  */
1287
          if (rval && rval == error_mark_node && deleted_p)
1288
            *deleted_p = true;
1289
          check_vdtor = false;
1290
        }
1291
    }
1292
 
1293
  vbases = CLASSTYPE_VBASECLASSES (ctype);
1294
  if (vbases && assign_p && move_p)
1295
    {
1296
      /* Should the spec be changed to allow vbases that only occur once?  */
1297
      if (diag)
1298
        error ("%qT has virtual bases, default move assignment operator "
1299
               "cannot be generated", ctype);
1300
      else if (deleted_p)
1301
        *deleted_p = true;
1302
    }
1303
  else if (!assign_p)
1304
    {
1305
      if (diag)
1306
        msg = ("virtual base %qT does not have a move constructor "
1307
               "or trivial copy constructor");
1308
      if (vbases && constexpr_p)
1309
        *constexpr_p = false;
1310
      FOR_EACH_VEC_ELT (tree, vbases, i, base_binfo)
1311
        {
1312
          tree basetype = BINFO_TYPE (base_binfo);
1313
          if (copy_arg_p)
1314
            argtype = build_stub_type (basetype, quals, move_p);
1315
          rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1316
 
1317
          process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
1318
                            constexpr_p, msg, basetype);
1319
          if (ctor_p && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype))
1320
            {
1321
              rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
1322
                                      NULL_TREE, flags, complain);
1323
              process_subob_fn (rval, false, spec_p, NULL,
1324
                                deleted_p, NULL, NULL,
1325
                                basetype);
1326
            }
1327
        }
1328
    }
1329
  if (!diag)
1330
    /* Leave msg null. */;
1331
  else if (assign_p)
1332
    msg = ("non-static data member %qD does not have a move "
1333
           "assignment operator or trivial copy assignment operator");
1334
  else
1335
    msg = ("non-static data member %qD does not have a move "
1336
           "constructor or trivial copy constructor");
1337
  walk_field_subobs (TYPE_FIELDS (ctype), fnname, sfk, quals,
1338
                     copy_arg_p, move_p, assign_p, spec_p, trivial_p,
1339
                     deleted_p, constexpr_p, msg, flags, complain);
1340
  if (ctor_p)
1341
    walk_field_subobs (TYPE_FIELDS (ctype), complete_dtor_identifier,
1342
                       sfk_destructor, TYPE_UNQUALIFIED, false,
1343
                       false, false, spec_p, NULL,
1344
                       deleted_p, NULL,
1345
                       NULL, flags, complain);
1346
 
1347
  pop_scope (scope);
1348
 
1349
  --cp_unevaluated_operand;
1350
  --c_inhibit_evaluation_warnings;
1351
}
1352
 
1353
/* DECL is a deleted function.  If it's implicitly deleted, explain why and
1354
   return true; else return false.  */
1355
 
1356
bool
1357
maybe_explain_implicit_delete (tree decl)
1358
{
1359
  /* If decl is a clone, get the primary variant.  */
1360
  decl = DECL_ORIGIN (decl);
1361
  gcc_assert (DECL_DELETED_FN (decl));
1362
  if (DECL_DEFAULTED_FN (decl))
1363
    {
1364
      /* Not marked GTY; it doesn't need to be GC'd or written to PCH.  */
1365
      static struct pointer_set_t *explained;
1366
 
1367
      special_function_kind sfk;
1368
      location_t loc;
1369
      bool informed;
1370
      tree ctype;
1371
 
1372
      if (!explained)
1373
        explained = pointer_set_create ();
1374
      if (pointer_set_insert (explained, decl))
1375
        return true;
1376
 
1377
      sfk = special_function_p (decl);
1378
      ctype = DECL_CONTEXT (decl);
1379
      loc = input_location;
1380
      input_location = DECL_SOURCE_LOCATION (decl);
1381
 
1382
      informed = false;
1383
      if (LAMBDA_TYPE_P (ctype))
1384
        {
1385
          informed = true;
1386
          if (sfk == sfk_constructor)
1387
            inform (DECL_SOURCE_LOCATION (decl),
1388
                    "a lambda closure type has a deleted default constructor");
1389
          else if (sfk == sfk_copy_assignment)
1390
            inform (DECL_SOURCE_LOCATION (decl),
1391
                    "a lambda closure type has a deleted copy assignment operator");
1392
          else
1393
            informed = false;
1394
        }
1395
      else if (DECL_ARTIFICIAL (decl)
1396
               && (sfk == sfk_copy_assignment
1397
                   || sfk == sfk_copy_constructor)
1398
               && (type_has_user_declared_move_constructor (ctype)
1399
                   || type_has_user_declared_move_assign (ctype)))
1400
        {
1401
          inform (0, "%q+#D is implicitly declared as deleted because %qT "
1402
                 "declares a move constructor or move assignment operator",
1403
                 decl, ctype);
1404
          informed = true;
1405
        }
1406
      if (!informed)
1407
        {
1408
          tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
1409
          bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1410
          tree scope = push_scope (ctype);
1411
          inform (0, "%q+#D is implicitly deleted because the default "
1412
                 "definition would be ill-formed:", decl);
1413
          pop_scope (scope);
1414
          synthesized_method_walk (ctype, sfk, const_p,
1415
                                   NULL, NULL, NULL, NULL, true);
1416
        }
1417
 
1418
      input_location = loc;
1419
      return true;
1420
    }
1421
  return false;
1422
}
1423
 
1424
/* DECL is a defaulted function which was declared constexpr.  Explain why
1425
   it can't be constexpr.  */
1426
 
1427
void
1428
explain_implicit_non_constexpr (tree decl)
1429
{
1430
  tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
1431
  bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1432
  bool dummy;
1433
  synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
1434
                           special_function_p (decl), const_p,
1435
                           NULL, NULL, NULL, &dummy, true);
1436
}
1437
 
1438
/* Implicitly declare the special function indicated by KIND, as a
1439
   member of TYPE.  For copy constructors and assignment operators,
1440
   CONST_P indicates whether these functions should take a const
1441
   reference argument or a non-const reference.  Returns the
1442
   FUNCTION_DECL for the implicitly declared function.  */
1443
 
1444
static tree
1445
implicitly_declare_fn (special_function_kind kind, tree type, bool const_p)
1446
{
1447
  tree fn;
1448
  tree parameter_types = void_list_node;
1449
  tree return_type;
1450
  tree fn_type;
1451
  tree raises = empty_except_spec;
1452
  tree rhs_parm_type = NULL_TREE;
1453
  tree this_parm;
1454
  tree name;
1455
  HOST_WIDE_INT saved_processing_template_decl;
1456
  bool deleted_p;
1457
  bool trivial_p;
1458
  bool constexpr_p;
1459
 
1460
  /* Because we create declarations for implicitly declared functions
1461
     lazily, we may be creating the declaration for a member of TYPE
1462
     while in some completely different context.  However, TYPE will
1463
     never be a dependent class (because we never want to do lookups
1464
     for implicitly defined functions in a dependent class).
1465
     Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
1466
     because we only create clones for constructors and destructors
1467
     when not in a template.  */
1468
  gcc_assert (!dependent_type_p (type));
1469
  saved_processing_template_decl = processing_template_decl;
1470
  processing_template_decl = 0;
1471
 
1472
  type = TYPE_MAIN_VARIANT (type);
1473
 
1474
  if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (type))
1475
    {
1476
      if (kind == sfk_destructor)
1477
        /* See comment in check_special_function_return_type.  */
1478
        return_type = build_pointer_type (void_type_node);
1479
      else
1480
        return_type = build_pointer_type (type);
1481
    }
1482
  else
1483
    return_type = void_type_node;
1484
 
1485
  switch (kind)
1486
    {
1487
    case sfk_destructor:
1488
      /* Destructor.  */
1489
      name = constructor_name (type);
1490
      break;
1491
 
1492
    case sfk_constructor:
1493
      /* Default constructor.  */
1494
      name = constructor_name (type);
1495
      break;
1496
 
1497
    case sfk_copy_constructor:
1498
    case sfk_copy_assignment:
1499
    case sfk_move_constructor:
1500
    case sfk_move_assignment:
1501
    {
1502
      bool move_p;
1503
      if (kind == sfk_copy_assignment
1504
          || kind == sfk_move_assignment)
1505
        {
1506
          return_type = build_reference_type (type);
1507
          name = ansi_assopname (NOP_EXPR);
1508
        }
1509
      else
1510
        name = constructor_name (type);
1511
 
1512
      if (const_p)
1513
        rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
1514
      else
1515
        rhs_parm_type = type;
1516
      move_p = (kind == sfk_move_assignment
1517
                || kind == sfk_move_constructor);
1518
      rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
1519
 
1520
      parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
1521
      break;
1522
    }
1523
    default:
1524
      gcc_unreachable ();
1525
    }
1526
 
1527
  synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
1528
                           &deleted_p, &constexpr_p, false);
1529
  /* Don't bother marking a deleted constructor as constexpr.  */
1530
  if (deleted_p)
1531
    constexpr_p = false;
1532
  /* A trivial copy/move constructor is also a constexpr constructor.  */
1533
  else if (trivial_p && cxx_dialect >= cxx0x
1534
           && (kind == sfk_copy_constructor
1535
               || kind == sfk_move_constructor))
1536
    gcc_assert (constexpr_p);
1537
 
1538
  if (!trivial_p && type_has_trivial_fn (type, kind))
1539
    type_set_nontrivial_flag (type, kind);
1540
 
1541
  /* Create the function.  */
1542
  fn_type = build_method_type_directly (type, return_type, parameter_types);
1543
  if (raises)
1544
    fn_type = build_exception_variant (fn_type, raises);
1545
  fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
1546
  DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
1547
  if (kind == sfk_constructor || kind == sfk_copy_constructor
1548
      || kind == sfk_move_constructor)
1549
    DECL_CONSTRUCTOR_P (fn) = 1;
1550
  else if (kind == sfk_destructor)
1551
    DECL_DESTRUCTOR_P (fn) = 1;
1552
  else
1553
    {
1554
      DECL_ASSIGNMENT_OPERATOR_P (fn) = 1;
1555
      SET_OVERLOADED_OPERATOR_CODE (fn, NOP_EXPR);
1556
    }
1557
 
1558
  /* If pointers to member functions use the least significant bit to
1559
     indicate whether a function is virtual, ensure a pointer
1560
     to this function will have that bit clear.  */
1561
  if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
1562
      && DECL_ALIGN (fn) < 2 * BITS_PER_UNIT)
1563
    DECL_ALIGN (fn) = 2 * BITS_PER_UNIT;
1564
 
1565
  /* Create the explicit arguments.  */
1566
  if (rhs_parm_type)
1567
    {
1568
      /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
1569
         want its type to be included in the mangled function
1570
         name.  */
1571
      tree decl = cp_build_parm_decl (NULL_TREE, rhs_parm_type);
1572
      TREE_READONLY (decl) = 1;
1573
      retrofit_lang_decl (decl);
1574
      DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
1575
      DECL_ARGUMENTS (fn) = decl;
1576
    }
1577
  /* Add the "this" parameter.  */
1578
  this_parm = build_this_parm (fn_type, TYPE_UNQUALIFIED);
1579
  DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
1580
  DECL_ARGUMENTS (fn) = this_parm;
1581
 
1582
  grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
1583
  set_linkage_according_to_type (type, fn);
1584
  rest_of_decl_compilation (fn, toplevel_bindings_p (), at_eof);
1585
  DECL_IN_AGGR_P (fn) = 1;
1586
  DECL_ARTIFICIAL (fn) = 1;
1587
  DECL_DEFAULTED_FN (fn) = 1;
1588
  if (cxx_dialect >= cxx0x)
1589
    {
1590
      DECL_DELETED_FN (fn) = deleted_p;
1591
      DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
1592
    }
1593
  DECL_NOT_REALLY_EXTERN (fn) = 1;
1594
  DECL_DECLARED_INLINE_P (fn) = 1;
1595
  gcc_assert (!TREE_USED (fn));
1596
 
1597
  /* Restore PROCESSING_TEMPLATE_DECL.  */
1598
  processing_template_decl = saved_processing_template_decl;
1599
 
1600
  return fn;
1601
}
1602
 
1603
/* Gives any errors about defaulted functions which need to be deferred
1604
   until the containing class is complete.  */
1605
 
1606
void
1607
defaulted_late_check (tree fn)
1608
{
1609
  /* Complain about invalid signature for defaulted fn.  */
1610
  tree ctx = DECL_CONTEXT (fn);
1611
  special_function_kind kind = special_function_p (fn);
1612
  bool fn_const_p = (copy_fn_p (fn) == 2);
1613
  tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p);
1614
 
1615
  if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
1616
                    TREE_TYPE (TREE_TYPE (implicit_fn)))
1617
      || !compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
1618
                     TYPE_ARG_TYPES (TREE_TYPE (implicit_fn))))
1619
    {
1620
      error ("defaulted declaration %q+D", fn);
1621
      error_at (DECL_SOURCE_LOCATION (fn),
1622
                "does not match expected signature %qD", implicit_fn);
1623
    }
1624
 
1625
  /* 8.4.2/2: If it is explicitly defaulted on its first declaration, it is
1626
     implicitly considered to have the same exception-specification as if
1627
     it had been implicitly declared.  */
1628
  if (DECL_DEFAULTED_IN_CLASS_P (fn))
1629
    {
1630
      tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
1631
      if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
1632
        {
1633
          maybe_instantiate_noexcept (fn);
1634
          if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)),
1635
                                  eh_spec, ce_normal))
1636
            error ("function %q+D defaulted on its first declaration "
1637
                   "with an exception-specification that differs from "
1638
                   "the implicit declaration %q#D", fn, implicit_fn);
1639
        }
1640
      TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
1641
      if (DECL_DECLARED_CONSTEXPR_P (implicit_fn))
1642
        {
1643
          /* Hmm...should we do this for out-of-class too? Should it be OK to
1644
             add constexpr later like inline, rather than requiring
1645
             declarations to match?  */
1646
          DECL_DECLARED_CONSTEXPR_P (fn) = true;
1647
          if (kind == sfk_constructor)
1648
            TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
1649
        }
1650
    }
1651
 
1652
  if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
1653
      && DECL_DECLARED_CONSTEXPR_P (fn))
1654
    {
1655
      if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
1656
        {
1657
          error ("explicitly defaulted function %q+D cannot be declared "
1658
                 "as constexpr because the implicit declaration is not "
1659
                 "constexpr:", fn);
1660
          explain_implicit_non_constexpr (fn);
1661
        }
1662
      DECL_DECLARED_CONSTEXPR_P (fn) = false;
1663
    }
1664
 
1665
  if (DECL_DELETED_FN (implicit_fn))
1666
    DECL_DELETED_FN (fn) = 1;
1667
}
1668
 
1669
/* Returns true iff FN can be explicitly defaulted, and gives any
1670
   errors if defaulting FN is ill-formed.  */
1671
 
1672
bool
1673
defaultable_fn_check (tree fn)
1674
{
1675
  special_function_kind kind = sfk_none;
1676
 
1677
  if (template_parm_scope_p ())
1678
    {
1679
      error ("a template cannot be defaulted");
1680
      return false;
1681
    }
1682
 
1683
  if (DECL_CONSTRUCTOR_P (fn))
1684
    {
1685
      if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
1686
        kind = sfk_constructor;
1687
      else if (copy_fn_p (fn) > 0
1688
               && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
1689
                   == void_list_node))
1690
        kind = sfk_copy_constructor;
1691
      else if (move_fn_p (fn))
1692
        kind = sfk_move_constructor;
1693
    }
1694
  else if (DECL_DESTRUCTOR_P (fn))
1695
    kind = sfk_destructor;
1696
  else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
1697
           && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR)
1698
    {
1699
      if (copy_fn_p (fn))
1700
        kind = sfk_copy_assignment;
1701
      else if (move_fn_p (fn))
1702
        kind = sfk_move_assignment;
1703
    }
1704
 
1705
  if (kind == sfk_none)
1706
    {
1707
      error ("%qD cannot be defaulted", fn);
1708
      return false;
1709
    }
1710
  else
1711
    {
1712
      tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
1713
      for (; t && t != void_list_node; t = TREE_CHAIN (t))
1714
        if (TREE_PURPOSE (t))
1715
          {
1716
            error ("defaulted function %q+D with default argument", fn);
1717
            break;
1718
          }
1719
      if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn)))
1720
        /* Defer checking.  */;
1721
      else if (!processing_template_decl)
1722
        defaulted_late_check (fn);
1723
 
1724
      return true;
1725
    }
1726
}
1727
 
1728
/* Add an implicit declaration to TYPE for the kind of function
1729
   indicated by SFK.  Return the FUNCTION_DECL for the new implicit
1730
   declaration.  */
1731
 
1732
tree
1733
lazily_declare_fn (special_function_kind sfk, tree type)
1734
{
1735
  tree fn;
1736
  /* Whether or not the argument has a const reference type.  */
1737
  bool const_p = false;
1738
 
1739
  switch (sfk)
1740
    {
1741
    case sfk_constructor:
1742
      CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
1743
      break;
1744
    case sfk_copy_constructor:
1745
      const_p = TYPE_HAS_CONST_COPY_CTOR (type);
1746
      CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
1747
      break;
1748
    case sfk_move_constructor:
1749
      CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
1750
      break;
1751
    case sfk_copy_assignment:
1752
      const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
1753
      CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
1754
      break;
1755
    case sfk_move_assignment:
1756
      CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
1757
      break;
1758
    case sfk_destructor:
1759
      CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
1760
      break;
1761
    default:
1762
      gcc_unreachable ();
1763
    }
1764
 
1765
  /* Declare the function.  */
1766
  fn = implicitly_declare_fn (sfk, type, const_p);
1767
 
1768
  /* [class.copy]/8 If the class definition declares a move constructor or
1769
     move assignment operator, the implicitly declared copy constructor is
1770
     defined as deleted.... */
1771
  if ((sfk == sfk_copy_assignment
1772
       || sfk == sfk_copy_constructor)
1773
      && (type_has_user_declared_move_constructor (type)
1774
          || type_has_user_declared_move_assign (type)))
1775
    DECL_DELETED_FN (fn) = true;
1776
 
1777
  /* For move variants, rather than declare them as deleted we just
1778
     don't declare them at all.  */
1779
  if (DECL_DELETED_FN (fn)
1780
      && (sfk == sfk_move_constructor
1781
          || sfk == sfk_move_assignment))
1782
    return NULL_TREE;
1783
 
1784
  /* A destructor may be virtual.  */
1785
  if (sfk == sfk_destructor
1786
      || sfk == sfk_move_assignment
1787
      || sfk == sfk_copy_assignment)
1788
    check_for_override (fn, type);
1789
  /* Add it to CLASSTYPE_METHOD_VEC.  */
1790
  add_method (type, fn, NULL_TREE);
1791
  /* Add it to TYPE_METHODS.  */
1792
  if (sfk == sfk_destructor
1793
      && DECL_VIRTUAL_P (fn)
1794
      && abi_version_at_least (2))
1795
    /* The ABI requires that a virtual destructor go at the end of the
1796
       vtable.  */
1797
    TYPE_METHODS (type) = chainon (TYPE_METHODS (type), fn);
1798
  else
1799
    {
1800
      /* G++ 3.2 put the implicit destructor at the *beginning* of the
1801
         TYPE_METHODS list, which cause the destructor to be emitted
1802
         in an incorrect location in the vtable.  */
1803
      if (warn_abi && sfk == sfk_destructor && DECL_VIRTUAL_P (fn))
1804
        warning (OPT_Wabi, "vtable layout for class %qT may not be ABI-compliant"
1805
                 "and may change in a future version of GCC due to "
1806
                 "implicit virtual destructor",
1807
                 type);
1808
      DECL_CHAIN (fn) = TYPE_METHODS (type);
1809
      TYPE_METHODS (type) = fn;
1810
    }
1811
  maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
1812
  if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
1813
      || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
1814
    /* Create appropriate clones.  */
1815
    clone_function_decl (fn, /*update_method_vec=*/true);
1816
 
1817
  return fn;
1818
}
1819
 
1820
/* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
1821
   as there are artificial parms in FN.  */
1822
 
1823
tree
1824
skip_artificial_parms_for (const_tree fn, tree list)
1825
{
1826
  if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1827
    list = TREE_CHAIN (list);
1828
  else
1829
    return list;
1830
 
1831
  if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1832
    list = TREE_CHAIN (list);
1833
  if (DECL_HAS_VTT_PARM_P (fn))
1834
    list = TREE_CHAIN (list);
1835
  return list;
1836
}
1837
 
1838
/* Given a FUNCTION_DECL FN and a chain LIST, return the number of
1839
   artificial parms in FN.  */
1840
 
1841
int
1842
num_artificial_parms_for (const_tree fn)
1843
{
1844
  int count = 0;
1845
 
1846
  if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1847
    count++;
1848
  else
1849
    return 0;
1850
 
1851
  if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1852
    count++;
1853
  if (DECL_HAS_VTT_PARM_P (fn))
1854
    count++;
1855
  return count;
1856
}
1857
 
1858
 
1859
#include "gt-cp-method.h"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.