Commit Graph

29 Commits

Author SHA1 Message Date
Benjamin Kramer 73f05d5776 [Sema] Fix assertion failure when checking for unused variables in a dependent context.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316177 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-19 19:07:13 +00:00
Benjamin Kramer cb0b66133f Re-land r315787, "[Sema] Warn about unused variables if we can constant evaluate the initializer."
The warnings in libc++ tests were fixed in the meantime.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315811 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-14 15:59:34 +00:00
NAKAMURA Takumi 9541b49afd Revert rL315787, "[Sema] Warn about unused variables if we can constant evaluate the initializer."
check-libcxx dislikes it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315806 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-14 14:46:04 +00:00
Benjamin Kramer ad2da73ac3 [Sema] Warn about unused variables if we can constant evaluate the initializer.
If the variable construction can be constant evaluated it doesn't have
side effects, so removing it is always safe. We only try to evaluate
variables that are unused, there should be no impact on compile time.

Differential Revision: https://reviews.llvm.org/D38678

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315787 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-14 01:30:49 +00:00
Alex Lorenz ec9c2858a9 Simplify the test case from r285289.
This commit simplifies and clarifies the test code
that was added in r285289. 

Suggested by David Blaikie.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285825 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-02 16:11:30 +00:00
Alex Lorenz 39bf9749a5 [Sema] -Wunused-variable warning for array variables should behave
similarly to scalar variables.

This commit makes the -Wunused-variable warning behaviour more consistent:
Now clang won't warn for array variables where it doesn't warn for scalar
variables.

rdar://24158862

Differential Revision: https://reviews.llvm.org/D25937


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285289 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-27 13:30:51 +00:00
Richard Smith 62034adc96 PR19558: don't produce an "unused variable" warning for a variable template partial specialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207260 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-25 19:21:40 +00:00
Richard Smith ce167d9989 PR19305: Don't issue -Wunused-variable warnings on variable templates. It's not
meaningful to odr-use the VarDecl inside a variable template. (Separately, it'd
be nice to track referenced-ness for templates, and warn on unused ones, but
that's really a distinct issue...)

Move a test that generates and tests a warning-suppressing error out to its own
test file, so it doesn't have weird effects on the other tests in the same file.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205448 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-02 18:28:36 +00:00
Richard Smith 93982a7557 PR8455: Handle an attribute between a goto label and a variable declaration per
the GNU documentation: the attribute only appertains to the label if it is
followed by a semicolon. Based on a patch by Aaron Ballman!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194869 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-15 22:45:29 +00:00
Matt Beaumont-Gay 19b6a707a8 Suppress -Wunused-variable for variables declared in headers, which may in
fact be defined and used in another TU.

Reshuffle some test cases because we suppress -Wunused-variable after we've
emitted an error.

This fixes PR15558.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179138 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-10 00:47:10 +00:00
David Blaikie 39e177692e Fix false positive in -Wunused-variable when a ctor call make involve cleanups.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166625 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-24 21:29:06 +00:00
David Blaikie 3ea19c8307 Fix a crash-on-invalid when parsing a reference to an invalid auto declaration
auto x((unknown));
  int& y = x;

would crash because we were not flagging 'x' as an invalid declaration here.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165675 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-10 23:15:05 +00:00
Rafael Espindola 1a5d35539a Improvements to the uninitialized variable warning: Check if the constructor
call is elidable or if the constructor is trivial instead of checking if it
is user declared.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147652 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-06 04:54:01 +00:00
Richard Smith e3499cae8e Fix PR10168: don't warn for unused non-dependent variables in both the template definition and each instantiation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133580 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-21 23:42:09 +00:00
Chandler Carruth 34d49471e0 Clean up the tests for warning about unused function results given the
appropriate attribute. Add a bit more testing that finds a pretty bad
regression (since ~forever) in this warning. Fix it with a nice 2 line
change. =]

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126098 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-21 00:56:56 +00:00
Douglas Gregor 268f89e02d Make #pragma unused work for static local variables.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118500 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-09 14:57:47 +00:00
Argyrios Kyrtzidis 1b2ad2fd9e Revert r114316, -Wunused-value enabled by default was intended.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114318 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-19 23:03:35 +00:00
Argyrios Kyrtzidis 6dff2288a8 Make -Wunused-value off by default, matching GCC. Fixes rdar://7126194.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114316 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-19 21:21:44 +00:00
Douglas Gregor ed8abf1832 Reinstate the fix for PR7556. A silly use of isTrivial() was
suppressing copies of objects with trivial copy constructors.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107857 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-08 06:14:04 +00:00
Douglas Gregor 84745677f6 Revert r107828 and r107827, the fix for PR7556, which seems to be
breaking bootstrap on Linux.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107837 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-07 23:37:33 +00:00
Douglas Gregor 63ef464c3f Do not use CXXZeroValueInitExpr for class types. Instead, use
CXXConstructExpr/CXXTemporaryObjectExpr/CXXNewExpr as
appropriate. Fixes PR7556, and provides a slide codegen improvement
when copy-initializing a POD class type from a value-initialized
temporary. Previously, we weren't eliding the copy.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107827 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-07 22:35:13 +00:00
Douglas Gregor a6a292b4dc Don't look into incomplete types when trying to warn about unused
variables. Fixes PR6948.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102436 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-27 16:20:13 +00:00
Douglas Gregor 4dffad64c5 When we have a dependent direct initializer but not a dependent
variable type, we can (and should) still check for completeness of the
variable's type. Do so, to work around an assertion that shows up in
Boost's shared_ptr.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95934 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-11 22:55:30 +00:00
Nuno Lopes cb1c77f90d support the warn_unused_result in C++ class methods
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92095 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-24 00:28:18 +00:00
Daniel Dunbar 80737ad5e0 Update tests to use %clang instead of 'clang', and forcibly disable use of '
clang ' or ' clang -cc1 ' or ' clang-cc ' in test lines (by substituting them to
garbage).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91460 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-15 22:01:24 +00:00
Anders Carlsson 58beed91d4 Fix PR5531.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89106 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-17 17:11:23 +00:00
Anders Carlsson 6a8b7f3f62 Add bug number.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86357 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-07 08:24:59 +00:00
Anders Carlsson f7613d5361 Don't treat variables with non-trivial ctors or dtors as unused. Fixes PR5407.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86352 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-07 07:26:56 +00:00
Douglas Gregor b5352cf949 Implement support for -Wunused-variable, from Oscar Bonilla!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83577 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-08 21:35:42 +00:00