1 // { dg-do assemble }
2 
3 // Copyright (C) 1999 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 5 Sep 1999 <nathan@acm.org>
5 
6 // [over.match] 13.3 tells us where overload resolution occurs.
7 // [over.match.call] 13.3.1.1 says that in
8 //  (...( postfix-expression )...) (expression-list)
9 // the postfix-expression must be the name of a function (amongst some other
10 // choices). This means comma and conditional exprs cannot be placed there.
11 // This clause is the only one I can find which bans
12 //  (cond ? fna : fnb) (arglist)
13 // which would be a major headache to have to implement.
14 // [over.over] 13.4 tells us when the use of a function name w/o arguments is
15 // resolved to the address of a particular function. These are determined by
16 // the context of the function name, and it does allow more complicated primary
17 // expressions.
18 
19 // Using a naked function name is rather strange, we used to warn about it
20 // (rather inconsistently), but subsequent changes broke the warning. Make
21 // sure that doesn't happen again.
22 
23 
24 void ovl (int);          // { dg-message "ovl|candidate expects" } candidate
25 void ovl (float);        // { dg-message "ovl|candidate expects" } candidate
26 void fn (int);
27 void fna (int);
28 
main(int argc,char ** argv)29 int main (int argc, char **argv)
30 {
31   void (*ptr) (int);
32   void (*vptr) ();
33 
34   (ovl) (1);                // ok
35   (&ovl) (1);               // ok
36   (ovl) ();                 // { dg-error "" } no matching candidates
37   (&ovl) ();                // { dg-error "" } not suitable for overload resolution
38 
39   // 13.3.1.1 indicates that the following are errors -- the primary expression
40   // is not the name of a function.
41   (0, ovl) (1);             // { dg-error "" } not suitable for overload resolution
42   (0, &ovl) (1);            // { dg-error "" } not suitable for overload resolution
43   (argc ? ovl : ovl) (1);   // { dg-error "" } not suitable for overload resolution
44   (argc ? &ovl : &ovl) (1); // { dg-error "" } not suitable for overload resolution
45 
46   (fn) (1);                 // ok
47   (&fn) (1);                // ok (no overload resolution)
48   (0, fn) (1);              // ok (no overload resolution)
49   (0, &fn) (1);             // ok (no overload resolution)
50   (argc ? fna : fn) (1);    // ok (no overload resolution)
51   (argc ? &fna : &fn) (1);  // ok (no overload resolution)
52 
53   ptr = (ovl);              // ok
54   ptr = (&ovl);             // ok
55   ptr = (0, ovl);           // ok { dg-error "no context" }
56   ptr = (0, &ovl);          // ok { dg-error "no context" }
57   ptr = (argc ? ovl : ovl); // ok { dg-error "no context" }
58   ptr = (argc ? &ovl : &ovl);// ok { dg-error "no context" }
59 
60   vptr = (ovl);              // { dg-error "" } no matching candidates
61   vptr = (&ovl);             // { dg-error "" } no matching candidates
62   vptr = (0, ovl);           // { dg-error "" } no matching candidates
63   vptr = (0, &ovl);          // { dg-error "" } no matching candidates
64   vptr = (argc ? ovl : ovl); // { dg-error "" } no matching candidates
65   vptr = (argc ? &ovl : &ovl);// { dg-error "" } no matching candidates
66 
67   ptr = (fn);
68   ptr = (&fn);
69   ptr = (0, fn);
70   ptr = (0, &fn);
71   ptr = (argc ? fna : fn);
72   ptr = (argc ? &fna : &fn);
73 
74   f;                // { dg-error "" } not a call
75   ovl;              // { dg-error "" } not suitable for overload
76   &ovl;             // { dg-error "" } not suitable for overload
77   (void)f;          // ok
78   (void)ovl;        // { dg-error "" } not suitable for overload
79   (void)&ovl;       // { dg-error "" } not suitable for overload
80   static_cast<void>(f);          // ok
81   static_cast<void>(ovl);        // { dg-error "" } not suitable for overload
82   static_cast<void>(&ovl);       // { dg-error "" } not suitable for overload
83   ((void)1, f);             // { dg-warning "" "" { xfail *-*-* } } not a call
84   ((void)1, ovl);           // { dg-error "" } not suitable for overload
85   ((void)1, &ovl);          // { dg-error "" } not suitable for overload
86   (void)((void)1, f);           // ok
87   (void)((void)1, ovl);         // { dg-error "" } not suitable for overload
88   (void)((void)1, &ovl);        // { dg-error "" } not suitable for overload
89 
90   return 0;
91 }
92