Bug 69736 - [4.9/5/6 Regression] "error: too few arguments to function" in c++14 but not c++11
Summary: [4.9/5/6 Regression] "error: too few arguments to function" in c++14 but not ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 4.9.4
Assignee: Patrick Palka
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-02-09 17:11 UTC by Marek Polacek
Modified: 2016-02-25 01:17 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-02-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2016-02-09 17:11:36 UTC
void fn1(bool = true) { (fn1)(); }

Is accepted with c++11 but not with c++14.  This is what creduce came up with.  clang++ accepts this code though it warns:
q.cc:1:23: warning: all paths through this function will call itself [-Winfinite-recursion]
Comment 1 Jakub Jelinek 2016-02-09 17:29:30 UTC
So has it ever been accepted with -std=c++1y?  Otherwise it would probably not be a regression...
Comment 2 Marek Polacek 2016-02-09 17:31:41 UTC
(In reply to Jakub Jelinek from comment #1)
> So has it ever been accepted with -std=c++1y?  Otherwise it would probably
> not be a regression...

Yes, gcc-48 accepts this with -std=gnu++1y or -std=c++1y.
Comment 3 Andrew Pinski 2016-02-09 18:11:33 UTC
C++14's () is special.
Comment 4 Andrew Pinski 2016-02-09 18:13:46 UTC
(fn1)();
is no longer the same as fn1();
But rather it returns an rvalue reference.  So it no longer includes the default arguments as part of the type.  That is function types don't have default arguments.
Comment 5 Jonathan Wakely 2016-02-09 19:30:51 UTC
In some contexts yes, but 5.1.1 [expr.prim.general] p6 says:

  A parenthesized expression is a primary expression whose type and value are
  identical to those of the enclosed expression. The presence of parentheses
  does not affect whether the expression is an lvalue. The parenthesized
  expression can be used in exactly the same contexts as those where the
  enclosed expression can be used, and with the same meaning, except as
  otherwise indicated.

I don't see anything indicating otherwise in [conf.func] or [expr.call] or [dcl.fct.default].
Comment 6 Patrick Palka 2016-02-18 23:21:02 UTC
Seems to only happen when fn1 is not overloaded.  If it is overloaded then the code is accepted in C++14:

void fn1(int, int);
void fn1(bool = true) { (fn1)(); }
Comment 7 Patrick Palka 2016-02-23 15:01:44 UTC
A patch is posted at: https://gcc.gnu.org/ml/gcc-patches/2016-02/msg01587.html
Comment 8 Patrick Palka 2016-02-25 01:14:59 UTC
Author: ppalka
Date: Thu Feb 25 01:14:27 2016
New Revision: 233691

URL: https://gcc.gnu.org/viewcvs?rev=233691&root=gcc&view=rev
Log:
Fix PR c++/69736

gcc/cp/ChangeLog:

	PR c++/69736
	* cp-tree.h (REF_PARENTHESIZED_P): Adjust documentation.
	(maybe_undo_parenthesized_ref): Declare.
	* semantics.c (maybe_undo_parenthesized_ref): Split out from
	check_return_expr.
	(finish_call_expr): Use it.
	* typeck.c (check_return_expr): Use it.
	* pt.c (tsubst_copy_and_build) [INDIRECT_REF]: Retain the
	REF_PARENTHESIZED_P flag.

gcc/testsuite/ChangeLog:

	PR c++/69736
	* g++.dg/cpp1y/paren2.C: New test.


Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/paren2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Patrick Palka 2016-02-25 01:17:26 UTC
Fixed for GCC 6.