llvm-project/clang/test/Misc
Nico Weber 728894340f Add -Wunused-local-typedef, a warning that finds unused local typedefs.
The warning warns on TypedefNameDecls -- typedefs and C++11 using aliases --
that are !isReferenced(). Since the isReferenced() bit on TypedefNameDecls
wasn't used for anything before this warning it wasn't always set correctly,
so this patch also adds a few missing MarkAnyDeclReferenced() calls in
various places for TypedefNameDecls.

This is made a bit complicated due to local typedefs possibly being used only
after their local scope has closed. Consider:

    template <class T>
    void template_fun(T t) {
      typename T::Foo s3foo;  // YYY
      (void)s3foo;
    }
    void template_fun_user() {
      struct Local {
        typedef int Foo;  // XXX
      } p;
      template_fun(p);
    }

Here the typedef in XXX is only used at end-of-translation unit, when YYY in
template_fun() gets instantiated. To handle this, typedefs that are unused when
their scope exits are added to a set of potentially unused typedefs, and that
set gets checked at end-of-TU. Typedefs that are still unused at that point then
get warned on. There's also serialization code for this set, so that the
warning works with precompiled headers and modules. For modules, the warning
is emitted when the module is built, for precompiled headers each time the
header gets used.

Finally, consider a function using C++14 auto return types to return a local
type defined in a header:

    auto f() {
      struct S { typedef int a; };
      return S();
    }

Here, the typedef escapes its local scope and could be used by only some
translation units including the header. To not warn on this, add a
RecursiveASTVisitor that marks all delcs on local types returned from auto
functions as referenced. (Except if it's a function with internal linkage, or
the decls are private and the local type has no friends -- in these cases, it
_is_ safe to warn.)

Several of the included testcases (most of the interesting ones) were provided
by Richard Smith.

(gcc's spelling -Wunused-local-typedefs is supported as an alias for this
warning.)

llvm-svn: 217298
2014-09-06 01:25:55 +00:00
..
Inputs Serialized diagnostic severity levels should be stable. 2014-03-03 18:29:52 +00:00
ast-dump-arm-attr.c Allow target-specific attributes to share a spelling between different attributes via the ParseKind field. Attributes will be given a common parsed attribute identifier (the AttributeList::AT_* enum), but retain distinct Attr subclasses. 2013-12-15 13:05:48 +00:00
ast-dump-attr.cpp AST Dump: print the Inherited flag on attributes 2014-05-31 04:05:57 +00:00
ast-dump-color.cpp Add -Wunused-local-typedef, a warning that finds unused local typedefs. 2014-09-06 01:25:55 +00:00
ast-dump-comment.cpp Comment parsing: fix a crash when dumping comment ast for a function template 2014-03-19 14:03:47 +00:00
ast-dump-decl.c Add the location of Decls to ast dump. 2014-04-02 05:48:29 +00:00
ast-dump-decl.cpp Fix/Improve SourceRange of explicitly defaulted members 2014-06-20 08:44:22 +00:00
ast-dump-decl.m Fixes PR18762, stop the StmtPrinter for ObjCPropertyRefExpr from crashing on 2014-02-06 23:26:23 +00:00
ast-dump-decl.mm Implement AST dumper for Decls. 2012-12-20 02:09:13 +00:00
ast-dump-lookups.cpp Modify behavior of -ast-dump-lookups: if -ast-dump is not also provided, dump 2014-08-11 22:11:07 +00:00
ast-dump-msp430-attr.c Allow target-specific attributes to share a spelling between different attributes via the ParseKind field. Attributes will be given a common parsed attribute identifier (the AttributeList::AT_* enum), but retain distinct Attr subclasses. 2013-12-15 13:05:48 +00:00
ast-dump-stmt.c Add indents to AST dumping and removed parenthesis from AST nodes. 2013-01-31 01:44:26 +00:00
ast-dump-stmt.cpp ASTDumper: fix dump of CXXCatchStmt 2013-09-04 14:35:00 +00:00
ast-dump-stmt.m Implement AST dumper for Decls. 2012-12-20 02:09:13 +00:00
ast-dump-templates.cpp When pretty-printing a declaration of a pack, put the ellipsis before the name 2014-07-23 03:17:06 +00:00
ast-dump-wchar.cpp Add indents to AST dumping and removed parenthesis from AST nodes. 2013-01-31 01:44:26 +00:00
ast-print-pragmas-xfail.cpp Adds a Pragma spelling for attributes to tablegen and makes use of it for loop 2014-06-13 17:57:25 +00:00
ast-print-pragmas.cpp Adds a Pragma spelling for attributes to tablegen and makes use of it for loop 2014-06-13 17:57:25 +00:00
attr-source-range.cpp Adding some test cases to test attribute-related source range diagnostics. This augments r214722, r214723 and r214507. 2014-08-12 14:00:40 +00:00
backend-optimization-failure.cpp Adjust test to handle fallout from r217102. 2014-09-03 23:20:58 +00:00
backend-stack-frame-diagnostics-fallback.cpp Implement -Wframe-larger-than backend diagnostic 2014-06-05 22:10:59 +00:00
backend-stack-frame-diagnostics.cpp Prevent link warnings due to -Wframe-larger-than= 2014-07-10 02:13:29 +00:00
caret-diags-macros.c Format strings: don't ever convert %+d to %lu. 2013-01-17 22:34:10 +00:00
caret-diags-scratch-buffer.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
dev-fd-fs.c This test passes on freebsd after r188178. Not exactly sure why. 2013-08-12 16:29:25 +00:00
diag-aka-types.cpp
diag-format.c Driver: bifurcate extended and basic MSC versioning 2014-07-16 03:13:50 +00:00
diag-line-wrapping.cpp Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diag-macro-backtrace.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diag-mapping.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diag-mapping2.c Improve specificity in the diag-mapping2.c test 2014-06-10 06:08:41 +00:00
diag-presumed.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diag-template-diffing-color.cpp Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diag-template-diffing-cxx98.cpp Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diag-template-diffing.cpp If a template argument is non-evaluable expression, use the profile ID to see 2014-07-26 02:10:52 +00:00
diag-trailing-null-bytes.cpp Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diag-verify.cpp Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
diagnostic-crash.cpp Test for LLVM r176911 2013-03-12 23:56:16 +00:00
driver-verify.c Tweak test run line for readability 2014-01-17 03:35:04 +00:00
emit-html-insert.c Revert "clang/test/Driver/crash-report.c: This requires rewriter for -frewrite-includes. [PR20321]" 2014-07-16 15:12:48 +00:00
emit-html.c Revert "clang/test/Driver/crash-report.c: This requires rewriter for -frewrite-includes. [PR20321]" 2014-07-16 15:12:48 +00:00
error-limit-multiple-notes.cpp When sorting overload candidates, sort arity mismatches in ascending 2014-05-01 21:15:24 +00:00
error-limit.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
freebsd-arm-size_t.c Initial support for FreeBSD on ARM. 2012-12-13 04:17:14 +00:00
include-stack-for-note-flag.cpp Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
integer-literal-printing.cpp StmtPrinter: Write large char values using \u or \U. 2013-02-08 22:30:27 +00:00
interpreter.c Add speculative clang-interpreter test 2014-05-05 06:22:21 +00:00
languageOptsOpenCL.cl [OpenCL] Variables in the constant address space must be initialized. 2014-01-03 14:16:55 +00:00
macro-backtrace.c
message-length.c
permissions.cpp Fix typo in test's REQUIRES line 2013-10-27 19:03:12 +00:00
predefines.c Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive. 2012-10-19 12:44:48 +00:00
remap-file.c
serialized-diags-frontend.c More workarounds for PR10867. 2012-12-05 22:33:14 +00:00
serialized-diags-no-category.c More workarounds for PR10867. 2012-12-05 22:33:14 +00:00
serialized-diags-no-issue.c
serialized-diags-single-issue.c
serialized-diags-stable.c Re-fix previous commit. 2014-03-03 19:46:28 +00:00
serialized-diags.c More workarounds for PR10867. 2012-12-05 22:33:14 +00:00
serialized-diags.h
serialized-diags.m Add regression test for serialized diagnostics for notes without locations. 2013-02-24 07:20:47 +00:00
show-diag-options.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
tabstop.c Fix FileCheck --check-prefix lines. 2013-08-12 12:51:05 +00:00
unnecessary-elipses.cpp only truncate source lines in text diagnostics when 2012-11-03 23:56:43 +00:00
unprintable.c Add 'not' to commands that are expected to fail. 2013-07-04 16:16:58 +00:00
verify.c Revert "Don't require -re suffix on -verify directives with regexes." 2013-12-14 01:07:05 +00:00
warn-in-system-header.c Extended VerifyDiagnosticConsumer to also verify source file for diagnostic. 2013-04-17 08:06:46 +00:00
warn-in-system-header.h
warn-sysheader.cpp Split out header integration tests 2014-05-04 13:00:32 +00:00
warning-flags-enabled.c
warning-flags-tree.c Add specific warning flags for GNU ext in Sema. 2013-09-18 23:23:17 +00:00
warning-flags.c Add a warning flag for an existing diagnostic. 2014-08-18 23:02:03 +00:00
win32-macho.c Remove dev/null redirect and x86 backend requirement from new test. 2014-06-11 20:19:07 +00:00
working-directory.c
wrong-encoding.c add test for r167063 2012-10-31 01:03:35 +00:00
wrong-encoding2.c fix bug in SourceColumnMap::startOfPreviousColumn 2012-11-03 21:21:14 +00:00