diff mbox

[C++] Minor fix for warn_args_num

Message ID 20150521134420.GL27320@redhat.com
State New
Headers show

Commit Message

Marek Polacek May 21, 2015, 1:44 p.m. UTC
I've just noticed that we print "note: declared here" even for builtins.
E.g.:

void
foo (void)
{
  __builtin_return ();
}

q.cc: In function ‘void foo()’:
q.cc:4:21: error: too few arguments to function ‘void __builtin_return(void*)’
   __builtin_return ();
                     ^
<built-in>: note: declared here

That doesn't seem to be too useful and the C FE doesn't do it.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-05-21  Marek Polacek  <polacek@redhat.com>

	* typeck.c (warn_args_num): Don't print "declare here" for builtins.


	Marek

Comments

Jason Merrill May 21, 2015, 2:11 p.m. UTC | #1
On 05/21/2015 09:44 AM, Marek Polacek wrote:
> +      if (!DECL_BUILT_IN (fndecl))

I think you want DECL_IS_BUILTIN.  OK with that change.

Jason
Marek Polacek May 21, 2015, 2:49 p.m. UTC | #2
On Thu, May 21, 2015 at 10:11:41AM -0400, Jason Merrill wrote:
> On 05/21/2015 09:44 AM, Marek Polacek wrote:
> >+      if (!DECL_BUILT_IN (fndecl))
> 
> I think you want DECL_IS_BUILTIN.  OK with that change.

Right.  With DECL_IS_BUILTIN we print

q.c:1:5: note: declared here
 int printf (const char *, ...);
     ^
even for

int printf (const char *, ...);
void
foo (void)
{
  printf ();
}

C FE uses DECL_BUILT_IN so it doesn't print the note, but I think
we want it in this case, so I'll fix it up there.  Thanks,

	Marek
diff mbox

Patch

diff --git gcc/cp/typeck.c gcc/cp/typeck.c
index ba99c30..8aadeca 100644
--- gcc/cp/typeck.c
+++ gcc/cp/typeck.c
@@ -3598,8 +3598,8 @@  warn_args_num (location_t loc, tree fndecl, bool too_many_p)
 		  ? G_("too many arguments to function %q#D")
 		  : G_("too few arguments to function %q#D"),
 		  fndecl);
-      inform (DECL_SOURCE_LOCATION (fndecl),
-	      "declared here");
+      if (!DECL_BUILT_IN (fndecl))
+	inform (DECL_SOURCE_LOCATION (fndecl), "declared here");
     }
   else
     {