Bug 44412 - [4.6 Regression] Another bogus set-but-not-used warning
Summary: [4.6 Regression] Another bogus set-but-not-used warning
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-04 00:35 UTC by Paolo Carlini
Modified: 2010-06-24 11:00 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
gcc46-pr44412.patch (682 bytes, patch)
2010-06-04 14:12 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Carlini 2010-06-04 00:35:03 UTC
This one causes tons of warnings in the libstdc++ testsuite (with -Wall in CXXFLAGS) and seems also bogus to me.

struct ratio
{
  static const int a = 3;
};

const int ratio::a;

int f()
{
  ratio r;
  return r.a;
}
Comment 1 Jakub Jelinek 2010-06-04 12:03:49 UTC
More complete testcase:

// PR c++/44412
// { dg-do compile }
// { dg-options "-Wunused" }

struct S
{
  static const int a = 3;
  static int b;
  int c;
};

const int S::a;
int S::b = 4;

int
f1 ()
{
  S s;
  return s.a;
}

int
f2 ()
{
  S s;
  return s.b;
}

void
f3 ()
{
  S s;
  s.c = 6;// { dg-warning "set but not used" }
}

int
f4 ()
{
  S s;
  s.c = 6;
  return s.c;
}

Guess we should mark the object through which a static data member is accessed,
because that access already marks the object as TREE_USED, yet it is not a set of the object.  Not sure where to do that though.  Calling methods or static methods apparently is handled already, in both cases build_new_method_call
-> build_this -> cp_build_unary_op ADDR_EXPR -> mark_lvalue_use -> mark_exp_read takes care of it:

// PR c++/44412
// { dg-do compile }
// { dg-options "-Wunused" }

struct S
{
  int foo ();
  static int bar ();
};

int S::foo ()
{
  return 5;
}

int S::bar ()
{
  return 6;
}

int
f1 ()
{
  S s;
  return s.foo ();
}

int
f2 ()
{
  S s;
  return s.bar ();
}
Comment 2 Jakub Jelinek 2010-06-04 14:12:46 UTC
Created attachment 20838 [details]
gcc46-pr44412.patch

Untested patch.
Comment 3 Jakub Jelinek 2010-06-04 18:46:13 UTC
Subject: Bug 44412

Author: jakub
Date: Fri Jun  4 18:45:07 2010
New Revision: 160290

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160290
Log:
	PR c++/44412
	* typeck.c (build_class_member_access_expr): Call mark_exp_read
	on object for static data members.

	* g++.dg/warn/Wunused-var-10.C: New test.
	* g++.dg/warn/Wunused-var-11.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-10.C
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-11.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Jakub Jelinek 2010-06-24 11:00:37 UTC
Fixed.