Bug 11945 - [3.4 Regression] Incorrect warnings issued for comma-expressions inside templates
Summary: [3.4 Regression] Incorrect warnings issued for comma-expressions inside templ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.0
Assignee: Nathan Sidwell
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2003-08-16 09:21 UTC by Gerald Pfeifer
Modified: 2004-01-17 04:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-08-16 11:49:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerald Pfeifer 2003-08-16 09:21:25 UTC
This bug only happens inside a template class or a template function,
but not inside a regular function.

Compile the following with g++ -W

  extern "C" void FormatDisk();
  template <class T>
  struct C {
    C(){ FormatDisk(), 0; }  // extraneous warning
  };
  template <class T>
  void f() { FormatDisk(), 0; } // extraneious warning
  void g() { FormatDisk(), 0; }

Incorrect warnings (Formatting a disk _is_ an effect, isn't it)?
  x.cc: In constructor `C<T>::C()':
  x.cc:4: warning: left-hand operand of comma expression has no effect
  x.cc: In function `void f()':
  x.cc:7: warning: left-hand operand of comma expression has no effect

This is a regression introduced around 2003-07-08, probably by Mark (according
to educated guesses using ChangeLogs and `cvs annotate`).

It is especially bad, as Solaris system headers use constructs like this.
Comment 1 Kriang Lerdsuwanakij 2003-08-16 11:49:45 UTC
Confirmed as a regression from 3.3.
Comment 2 Andrew Pinski 2003-08-16 12:43:13 UTC
This is a dup of bug 11512.

*** This bug has been marked as a duplicate of 11512 ***
Comment 3 Gerald Pfeifer 2003-08-18 10:12:41 UTC
This is not a real duplicate, in that the fix for PR11512 causes problems with
the testcase of this PR:

 % gccvs x.cc -c -Wall
 x.cc: In function `void g()':
 x.cc:11: warning: right-hand operand of comma has no effect

If don't think we should warn in this case, but _if_ we do, we should
consistenly warn in all three cases, not just the ones involving templates.
Comment 4 Nathan Sidwell 2003-08-20 17:58:56 UTC
2003-08-19  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/11945
	* pt.c (build_non_dependent_expr): Look inside COND_EXPR and
	COMPOUND_EXPR.
	* semantics.c (finish_expr_stmt): Always convert to void.
	* typeck.c (build_x_compound_exp): Always convert to void.
Comment 5 GCC Commits 2003-08-20 18:00:14 UTC
Subject: Bug 11945

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2003-08-20 18:00:09

Modified files:
	gcc/cp         : ChangeLog pt.c semantics.c typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/warn: noeffect2.C 

Log message:
	cp:
	PR c++/11945
	* pt.c (build_non_dependent_expr): Look inside COND_EXPR and
	COMPOUND_EXPR.
	* semantics.c (finish_expr_stmt): Always convert to void.
	* typeck.c (build_x_compound_exp): Always convert to void.
	testsuite:
	PR c++/11945
	* g++.dg/warn/noeffect2.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3612&r2=1.3613
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.761&r2=1.762
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.348&r2=1.349
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.493&r2=1.494
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2982&r2=1.2983
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/noeffect2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1