Files
llvm-project/clang-tools-extra/test/clang-tidy/google-namespaces.cpp
Alexander Kornienko 1ca0e322a2 Make google-build-using-namespace skip std::.*literals
Summary:
C++14 added a couple of user-defined literals in the standard library. E.g.
std::chrono_literals and std::literals::chrono_literals . Using them
requires a using directive so do not warn in google-build-using-namespace
if namespace name starts with "std::" and ends with "literals".

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Patch by Martin Ejdestig!

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

llvm-svn: 303085
2017-05-15 17:37:48 +00:00

53 lines
2.0 KiB
C++

// RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:"
#include "Inputs/google-namespaces.h"
// CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces]
using namespace spaaaace;
// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
using spaaaace::core; // no-warning
namespace std {
inline namespace literals {
inline namespace chrono_literals {
}
inline namespace complex_literals {
}
inline namespace string_literals {
}
}
}
using namespace std::chrono_literals; // no-warning
using namespace std::complex_literals; // no-warning
using namespace std::literals; // no-warning
using namespace std::literals::chrono_literals; // no-warning
using namespace std::literals::complex_literals; // no-warning
using namespace std::literals::string_literals; // no-warning
using namespace std::string_literals; // no-warning
namespace literals {}
using namespace literals;
// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
namespace foo {
inline namespace literals {
inline namespace bar_literals {}
}
}
using namespace foo::literals;
// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
using namespace foo::bar_literals;
// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
using namespace foo::literals::bar_literals;
// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
namespace foo_literals {}
using namespace foo_literals;
// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]