public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25814]  New: Request for new warning
@ 2006-01-17  0:42 Raimund dot Merkert at baesystems dot com
  2006-01-17  0:58 ` [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Raimund dot Merkert at baesystems dot com @ 2006-01-17  0:42 UTC (permalink / raw)
  To: gcc-bugs

I'd like to request a warning to notify that a statement like "X x(const Y&)"
is parsed as function declaration and not a definition of variable x. See the
code below.

At least as couple of PRs have been filed (9217,19503) on this topic.
I've just spent at least 2 hrs trying to figure out why my constructor and
destructor were not called and did not show up in the assembly code either. 

I think this particular problem might affect users that use the
resource-acquisition idiom. The real problem is that the code compiles and
links and runs without problems, except it doesn't actually work.


#include <cstdio>

struct Y {};

struct X {
  inline X (const Y&)
  {}

  inline ~X ()
  {
    ::std::printf("1\n");
  }

};

int main()
{
  X x(Y());
  return 0;
}


-- 
           Summary: Request for new warning
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Raimund dot Merkert at baesystems dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations
  2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
@ 2006-01-17  0:58 ` pinskia at gcc dot gnu dot org
  2006-01-17  4:01 ` gdr at cs dot tamu dot edu
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-17  0:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-01-17 00:58 -------
Maybe if more C++ books actually talked about this issue, there would not be a
problem (sorry I could not resists).  Also warning about very valid and defined
code even if it is a common mistake that beginers make.  I would rather have
people actually taught this rule than GCC warning about it.

"The real problem is that the code compiles and links and runs without
problems, except it doesn't actually work."

that should say doesn't actually work the way the person is expecting so it is
working as the C++ standard says it should work.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
            Summary|Request for new warning     |Request for warning for
                   |                            |parser ambiguity of function
                   |                            |declarations and variable
                   |                            |declarations with
                   |                            |initializations


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations
  2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
  2006-01-17  0:58 ` [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations pinskia at gcc dot gnu dot org
@ 2006-01-17  4:01 ` gdr at cs dot tamu dot edu
  2006-01-17 12:33 ` Raimund dot Merkert at baesystems dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: gdr at cs dot tamu dot edu @ 2006-01-17  4:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from gdr at cs dot tamu dot edu  2006-01-17 04:01 -------
Subject: Re:  Request for warning for parser ambiguity of function declarations
and variable declarations with initializations

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| Maybe if more C++ books actually talked about this issue, there would not be
a
| problem (sorry I could not resists).

C++ books do take about it -- just check out the good ones.  This very
problem, if you check out writings from Bjarne or me (see, e.g.,
our proposal for "generalized initializer list" for discussions), is a
problem inherited from the C syntax which permits redundant
parenthesis in declarations, exacerbed by the functional notation.
Check out details from D&E. 

|  Also warning about very valid and defined
| code even if it is a common mistake that beginers make.  I would rather have
| people actually taught this rule than GCC warning about it.

this is somehow hard to diagnose, but I guess one could engineer the
front-end to remember redundant parens, but it would be rather low
priority for me.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations
  2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
  2006-01-17  0:58 ` [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations pinskia at gcc dot gnu dot org
  2006-01-17  4:01 ` gdr at cs dot tamu dot edu
@ 2006-01-17 12:33 ` Raimund dot Merkert at baesystems dot com
  2006-02-02 19:54 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Raimund dot Merkert at baesystems dot com @ 2006-01-17 12:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from Raimund dot Merkert at baesystems dot com  2006-01-17 12:32 -------
I would not consider myself a beginner, but I'm no c++ language laywer either.
Usually the problem will get caught as soon as you try to invoke a method, but
if it's something like a guard object, without methods, then it can be a
problem. 
This is such an infrequent event (I think it happened to me before, years ago)
it's easy to forget about this rule and no amount of teaching about it in books
will help ( and I do use the Stroustrup book ).


I agree that it is probably hard to fix because it's a grammar problem, but
might it be possible to warn about a locally unused declaration? Maybe it makes
sense to warn about any local declaration (I've never really seen those)? Or
maybe it's a statement that has no effect?

Priority-wise, it's probably low considering the rare occurrence.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations
  2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
                   ` (2 preceding siblings ...)
  2006-01-17 12:33 ` Raimund dot Merkert at baesystems dot com
@ 2006-02-02 19:54 ` pinskia at gcc dot gnu dot org
  2006-03-08  5:07 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-02 19:54 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P5


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations
  2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
                   ` (3 preceding siblings ...)
  2006-02-02 19:54 ` pinskia at gcc dot gnu dot org
@ 2006-03-08  5:07 ` bangerth at dealii dot org
  2006-11-14 15:36 ` wolfgang dot roemer at gmx dot net
  2006-11-14 15:52 ` Raimund dot Merkert at baesystems dot com
  6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2006-03-08  5:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bangerth at dealii dot org  2006-03-08 05:07 -------
I think we can confirm the problem. I doubt anyone will come around to
actually taking this on anytime soon, though...

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-03-08 05:07:27
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations
  2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
                   ` (4 preceding siblings ...)
  2006-03-08  5:07 ` bangerth at dealii dot org
@ 2006-11-14 15:36 ` wolfgang dot roemer at gmx dot net
  2006-11-14 15:52 ` Raimund dot Merkert at baesystems dot com
  6 siblings, 0 replies; 8+ messages in thread
From: wolfgang dot roemer at gmx dot net @ 2006-11-14 15:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from wolfgang dot roemer at gmx dot net  2006-11-14 15:35 -------
Raimund.Merkert@baesystems.com wrote:
"Usually the problem will get caught as soon as you try to invoke a method, but
if it's something like a guard object, without methods, then it can be a
problem."

At least in this case there should be a warning if -Wunused-function is used,
shouldn't it?


-- 

wolfgang dot roemer at gmx dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wolfgang dot roemer at gmx
                   |                            |dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations
  2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
                   ` (5 preceding siblings ...)
  2006-11-14 15:36 ` wolfgang dot roemer at gmx dot net
@ 2006-11-14 15:52 ` Raimund dot Merkert at baesystems dot com
  6 siblings, 0 replies; 8+ messages in thread
From: Raimund dot Merkert at baesystems dot com @ 2006-11-14 15:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from Raimund dot Merkert at baesystems dot com  2006-11-14 15:52 -------
It does not seem to warn about unused functions. I also tried the following
test case where 4.0.0 (solaris)  does not warn even about foo ( I guess because
it's referenced in Y's constructor?)

gcc  -Wunused-function test.cpp 


#include <cstdio>

static void foo() {}

struct Y {
  Y() { foo(); }
};

struct X {
  inline X (const Y&)
  {}

  inline ~X ()
  {
    ::std::printf("1\n");
  }

};

int main()
{
  X x(Y());
  return 0;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25814


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-11-14 15:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-17  0:42 [Bug c++/25814] New: Request for new warning Raimund dot Merkert at baesystems dot com
2006-01-17  0:58 ` [Bug c++/25814] Request for warning for parser ambiguity of function declarations and variable declarations with initializations pinskia at gcc dot gnu dot org
2006-01-17  4:01 ` gdr at cs dot tamu dot edu
2006-01-17 12:33 ` Raimund dot Merkert at baesystems dot com
2006-02-02 19:54 ` pinskia at gcc dot gnu dot org
2006-03-08  5:07 ` bangerth at dealii dot org
2006-11-14 15:36 ` wolfgang dot roemer at gmx dot net
2006-11-14 15:52 ` Raimund dot Merkert at baesystems dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).