[PATCH] D39430: [clangd] various fixes

2017-12-03 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

> - Look up in parent directories for a .clang-format file. Use "LLVM" as 
> fallback style.
> - Move cached fixits to ClangdServer, remove fixits once the client closes 
> the document.
> - Fix translations between LSP rows/cols (0-based) and clang row/cols 
> (1-based).

I'd rather keep one commit per fix or feature. I would think the clang-format 
part should be one commit/review on its own. But I'm not very familiar with the 
practices here so I'll let others comment.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D39430



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38425: [clangd] Document highlights for clangd

2017-12-03 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle requested changes to this revision.
malaperle added inline comments.
This revision now requires changes to proceed.



Comment at: clangd/ClangdServer.cpp:528
+  Value = llvm::make_error(
+  "invalid AST",
+  llvm::errc::invalid_argument);

Invalid



Comment at: clangd/ClangdServer.cpp:530
+  llvm::errc::invalid_argument);
+Value = make_tagged(clangd::findDocumentHighlights(*AST, Pos, Logger), 
TaggedFS.Tag);
+  });

It trips here with assertions enabled because we haven't checked the previous 
"Value" for error before, sigh.
Expected must be checked before access or destruction.
Expected value was in success state. (Note: Expected values in success 
mode must still be checked prior to being destroyed).

How about this:
```
  std::vector Result;
  llvm::Optional Err;
  Resources->getAST().get()->runUnderLock([Pos, , ,
   this](ParsedAST *AST) {
if (!AST)
  Err = llvm::make_error("Invalid AST",
llvm::errc::invalid_argument);
Result = clangd::findDocumentHighlights(*AST, Pos, Logger);
  });

  if (Err)
return std::move(*Err);

  return make_tagged(Result, TaggedFS.Tag);
```
The tests pass for me with this.



Comment at: clangd/Protocol.cpp:372
+
+
+

Too many new lines. Only keep one.



Comment at: clangd/Protocol.h:568
+struct DocumentHighlight {
+  /*
+   *

Use /// like other places



Comment at: clangd/Protocol.h:575
+  /**
+   * The highlight kind, default is DocumentHighlightKind.Text.
+   */

Use /// like other places


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38425



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319638 - [analyzer] Don't treat lambda-captures float constexprs as undefined

2017-12-03 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Sun Dec  3 20:46:47 2017
New Revision: 319638

URL: http://llvm.org/viewvc/llvm-project?rev=319638=rev
Log:
[analyzer] Don't treat lambda-captures float constexprs as undefined

RegionStore has special logic to evaluate captured constexpr variables.
However, if the constexpr initializer cannot be evaluated as an integer, the
value is treated as undefined. This leads to false positives when, for example,
a constexpr float is captured by a lambda.

To fix this, treat a constexpr capture that cannot be evaluated as unknown
rather than undefined.

rdar://problem/35784662

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/lambdas.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=319638=319637=319638=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Sun Dec  3 20:46:47 2017
@@ -1864,11 +1864,18 @@ SVal RegionStoreManager::getBindingForVa
 return svalBuilder.getRegionValueSymbolVal(R);
 
   // Is 'VD' declared constant?  If so, retrieve the constant value.
-  if (VD->getType().isConstQualified())
-if (const Expr *Init = VD->getInit())
+  if (VD->getType().isConstQualified()) {
+if (const Expr *Init = VD->getInit()) {
   if (Optional V = svalBuilder.getConstantVal(Init))
 return *V;
 
+  // If the variable is const qualified and has an initializer but
+  // we couldn't evaluate initializer to a value, treat the value as
+  // unknown.
+  return UnknownVal();
+}
+  }
+
   // This must come after the check for constants because closure-captured
   // constant variables may appear in UnknownSpaceRegion.
   if (isa(MS))

Modified: cfe/trunk/test/Analysis/lambdas.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lambdas.cpp?rev=319638=319637=319638=diff
==
--- cfe/trunk/test/Analysis/lambdas.cpp (original)
+++ cfe/trunk/test/Analysis/lambdas.cpp Sun Dec  3 20:46:47 2017
@@ -337,6 +337,16 @@ void captureByReference() {
   lambda2();
 }
 
+void testCapturedConstExprFloat() {
+  constexpr float localConstant = 4.0;
+  auto lambda = []{
+// Don't treat localConstant as containing a garbage value
+float copy = localConstant; // no-warning
+(void)copy;
+  };
+
+  lambda();
+}
 
 // CHECK: [B2 (ENTRY)]
 // CHECK:   Succs (1): B1


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35894: [clangd] Code hover for Clangd

2017-12-03 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle accepted this revision.
malaperle added a comment.

This looks good to me. @ilya-biryukov Any objections?
I think we can do further iterations later to handle macros and other specific 
cases (multiple Decls at the position, etc) . It's already very useful 
functionality.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40671: [clang-tidy] Support specific checks for NOLINT directive

2017-12-03 Thread Anton via Phabricator via cfe-commits
xgsa added inline comments.



Comment at: docs/clang-tidy/index.rst:280
+lint-command
+lint-command lint-args
+

aaron.ballman wrote:
> This should have a subscript `opt` following `lint-args` to denote that the 
> args are optional. I think you can achieve that with:
> ```
> lint-args\ :sub:`opt`
> ```
Sorry, I am not very familiar with Sphinx, but
```
\ :sub:`opt`
```
seems doesn't work inside `parsed-literal` block (I have searched through the 
llvm docs and found a few similar places, which uses such construction in 
`parsed-literal` block, and it is not rendered properly even on official web 
site).
Here `parsed-literal` block is used to render a quote-like block with custom 
formatting, so the whole grammar is shown as a single entity, and I cannot 
achieve this with the other constructs. 
To show that `lint-args` is optional I split this grammar rule into 2:
```
lint-command
lint-command lint-args
```

Isn't it enough or are there any suggestions how to handle this?


https://reviews.llvm.org/D40671



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40671: [clang-tidy] Support specific checks for NOLINT directive

2017-12-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from a minor commenting nit, this LGTM. Thanks!




Comment at: docs/clang-tidy/index.rst:280
+lint-command
+lint-command lint-args
+

This should have a subscript `opt` following `lint-args` to denote that the 
args are optional. I think you can achieve that with:
```
lint-args\ :sub:`opt`
```


https://reviews.llvm.org/D40671



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40671: [clang-tidy] Support specific checks for NOLINT directive

2017-12-03 Thread Anton via Phabricator via cfe-commits
xgsa updated this revision to Diff 125292.
xgsa added a comment.

A typo in documentation was fixed.


https://reviews.llvm.org/D40671

Files:
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/nolint.cpp
  test/clang-tidy/nolintnextline.cpp

Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -250,6 +250,51 @@
   value:   'some value'
   ...
 
+While :program:`clang-tidy` diagnostics are intended to call out code that does
+not adhere to a coding standard, or is otherwise problematic in some way, there
+are times when it is more appropriate to silence the diagnostic instead of 
+changing the semantics of the code. In such circumstances, the ``NOLINT`` or
+``NOLINTNEXTLINE`` comments can be used to silence the diagnostic. For example:
+
+.. code-block:: c++
+
+  class Foo
+  {
+// Skip all the diagnostics for the line
+Foo(int param); // NOLINT
+
+// Skip only the specified checks for the line
+Foo(double param); // NOLINT(google-explicit-constructor, google-runtime-int)
+
+// Skip only the specified diagnostics for the next line
+// NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int)
+Foo(bool param); 
+  };
+
+The formal syntax of ``NOLINT``/``NOLINTNEXTLINE`` is the following:
+
+.. parsed-literal::
+
+  lint-comment:
+lint-command
+lint-command lint-args
+
+  lint-args:
+**(** check-name-list **)**
+
+  check-name-list:
+*check-name*
+check-name-list **,** *check-name*
+
+  lint-command:
+**NOLINT**
+**NOLINTNEXTLINE**
+
+Note that whitespaces between ``NOLINT``/``NOLINTNEXTLINE`` and the opening
+parenthesis are not allowed (in this case the comment will be treated just as
+``NOLINT``/``NOLINTNEXTLINE``), whereas in check names list (inside
+the parenthesis) whitespaces can be used and will be ignored.
+
 .. _LibTooling: http://clang.llvm.org/docs/LibTooling.html
 .. _How To Setup Tooling For LLVM: http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
 
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -256,6 +256,8 @@
   - `hicpp-use-nullptr `_
   - `hicpp-vararg `_
 
+- Added the ability to suppress specific checks (or all checks) in a ``NOLINT`` or ``NOLINTNEXTLINE`` comment.
+
 Improvements to include-fixer
 -
 
Index: test/clang-tidy/nolint.cpp
===
--- test/clang-tidy/nolint.cpp
+++ test/clang-tidy/nolint.cpp
@@ -13,7 +13,18 @@
 
 class B { B(int i); }; // NOLINT
 
-class C { C(int i); }; // NOLINT(we-dont-care-about-categories-yet)
+class C { C(int i); }; // NOLINT(for-some-other-check)
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+class C1 { C1(int i); }; // NOLINT(*)
+
+class C2 { C2(int i); }; // NOLINT(not-closed-bracket-is-treated-as-skip-all
+
+class C3 { C3(int i); }; // NOLINT(google-explicit-constructor)
+
+class C4 { C4(int i); }; // NOLINT(some-check, google-explicit-constructor)
+
+class C5 { C5(int i); }; // NOLINT without-brackets-skip-all, another-check
 
 void f() {
   int i;
@@ -35,4 +46,4 @@
 #define DOUBLE_MACRO MACRO(H) // NOLINT
 DOUBLE_MACRO
 
-// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
+// CHECK-MESSAGES: Suppressed 12 warnings (12 NOLINT)
Index: test/clang-tidy/nolintnextline.cpp
===
--- test/clang-tidy/nolintnextline.cpp
+++ test/clang-tidy/nolintnextline.cpp
@@ -4,8 +4,24 @@
 // NOLINTNEXTLINE
 class B { B(int i); };
 
-// NOLINTNEXTLINE(we-dont-care-about-categories-yet)
+// NOLINTNEXTLINE(for-some-other-check)
 class C { C(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+// NOLINTNEXTLINE(*)
+class C1 { C1(int i); };
+
+// NOLINTNEXTLINE(not-closed-bracket-is-treated-as-skip-all
+class C2 { C2(int i); };
+
+// NOLINTNEXTLINE(google-explicit-constructor)
+class C3 { C3(int i); };
+
+// NOLINTNEXTLINE(some-check, google-explicit-constructor)
+class C4 { C4(int i); };
+
+// NOLINTNEXTLINE without-brackets-skip-all, another-check
+class C5 { C5(int i); };
 
 
 // NOLINTNEXTLINE
@@ -28,6 +44,6 @@
 // NOLINTNEXTLINE
 MACRO_NOARG
 
-// CHECK-MESSAGES: Suppressed 4 warnings (4 NOLINT)
+// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
 
 // RUN: %check_clang_tidy %s google-explicit-constructor %t --
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ 

[PATCH] D40671: [clang-tidy] Support specific checks for NOLINT directive

2017-12-03 Thread Anton via Phabricator via cfe-commits
xgsa updated this revision to Diff 125291.
xgsa added a comment.

Updated documentation and comments in code.


https://reviews.llvm.org/D40671

Files:
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/nolint.cpp
  test/clang-tidy/nolintnextline.cpp

Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -250,6 +250,51 @@
   value:   'some value'
   ...
 
+While :program:`clang-tidy` diagnostics are intended to call out code that does
+not adhere to a coding standard, or is otherwise problematic in some way, there
+are times when it is more appropriate to silence the diagnostic instead of 
+changing the semantics of the code. In such circumstances, the ``NOLINT`` or
+``NOLINTNEXTLINE`` comments can be used to silence the diagnostic. For example:
+
+.. code-block:: c++
+
+  class Foo
+  {
+// Skip all the diagnostics for the line
+Foo(int param); // NOLINT
+
+// Skip only the specified checks for the line
+Foo(double param); // NOLINT(google-explicit-constructor, google-runtime-int)
+
+// Skip only the specified diagnostics for the next line
+// NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int)
+Foo(bool param); 
+  };
+
+The formal syntax of ``NOLINT``/``NOLINTNEXTLINE`` is the following:
+
+.. parsed-literal::
+
+  lint-comment:
+lint-command
+lint-command lint-args
+
+  lint-args:
+**(** check-name-list **)**
+
+  check-name-list:
+*check-name*
+check-name-list **,** *check-name*
+
+  lint-command:
+**NOLINT**
+**NOLINTNEXTLINE**
+
+Note that whitespaces between ``NOLINT``/``NOLINTNEXTLINE`` and the opening
+parenthesis are not allowed (in this case the comment will be threated just as
+``NOLINT``/``NOLINTNEXTLINE``), whereas in check names list (inside
+the parenthesis) whitespaces can be used and will be ignored.
+
 .. _LibTooling: http://clang.llvm.org/docs/LibTooling.html
 .. _How To Setup Tooling For LLVM: http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
 
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -256,6 +256,8 @@
   - `hicpp-use-nullptr `_
   - `hicpp-vararg `_
 
+- Added the ability to suppress specific checks (or all checks) in a ``NOLINT`` or ``NOLINTNEXTLINE`` comment.
+
 Improvements to include-fixer
 -
 
Index: test/clang-tidy/nolint.cpp
===
--- test/clang-tidy/nolint.cpp
+++ test/clang-tidy/nolint.cpp
@@ -13,7 +13,18 @@
 
 class B { B(int i); }; // NOLINT
 
-class C { C(int i); }; // NOLINT(we-dont-care-about-categories-yet)
+class C { C(int i); }; // NOLINT(for-some-other-check)
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+class C1 { C1(int i); }; // NOLINT(*)
+
+class C2 { C2(int i); }; // NOLINT(not-closed-bracket-is-treated-as-skip-all
+
+class C3 { C3(int i); }; // NOLINT(google-explicit-constructor)
+
+class C4 { C4(int i); }; // NOLINT(some-check, google-explicit-constructor)
+
+class C5 { C5(int i); }; // NOLINT without-brackets-skip-all, another-check
 
 void f() {
   int i;
@@ -35,4 +46,4 @@
 #define DOUBLE_MACRO MACRO(H) // NOLINT
 DOUBLE_MACRO
 
-// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
+// CHECK-MESSAGES: Suppressed 12 warnings (12 NOLINT)
Index: test/clang-tidy/nolintnextline.cpp
===
--- test/clang-tidy/nolintnextline.cpp
+++ test/clang-tidy/nolintnextline.cpp
@@ -4,8 +4,24 @@
 // NOLINTNEXTLINE
 class B { B(int i); };
 
-// NOLINTNEXTLINE(we-dont-care-about-categories-yet)
+// NOLINTNEXTLINE(for-some-other-check)
 class C { C(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+// NOLINTNEXTLINE(*)
+class C1 { C1(int i); };
+
+// NOLINTNEXTLINE(not-closed-bracket-is-treated-as-skip-all
+class C2 { C2(int i); };
+
+// NOLINTNEXTLINE(google-explicit-constructor)
+class C3 { C3(int i); };
+
+// NOLINTNEXTLINE(some-check, google-explicit-constructor)
+class C4 { C4(int i); };
+
+// NOLINTNEXTLINE without-brackets-skip-all, another-check
+class C5 { C5(int i); };
 
 
 // NOLINTNEXTLINE
@@ -28,6 +44,6 @@
 // NOLINTNEXTLINE
 MACRO_NOARG
 
-// CHECK-MESSAGES: Suppressed 4 warnings (4 NOLINT)
+// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
 
 // RUN: %check_clang_tidy %s google-explicit-constructor %t --
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ 

[PATCH] D40671: [clang-tidy] Support specific checks for NOLINT directive

2017-12-03 Thread Anton via Phabricator via cfe-commits
xgsa marked 2 inline comments as done.
xgsa added inline comments.



Comment at: docs/clang-tidy/index.rst:270
+// Skip only the specified diagnostics for the next line
+// NOLINTNEXTLINE (google-explicit-constructor, google-runtime-int)
+Foo(bool param); 

aaron.ballman wrote:
> Is the space before the `(` intended?
No, it's a mistake, thank you.


https://reviews.llvm.org/D40671



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319632 - [ASTImporter] Add unit tests for UsingDecl and UsingShadowDecl

2017-12-03 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Sun Dec  3 08:04:07 2017
New Revision: 319632

URL: http://llvm.org/viewvc/llvm-project?rev=319632=rev
Log:
[ASTImporter] Add unit tests for UsingDecl and UsingShadowDecl

Patch by Kareem Khazem!

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


Modified:
cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=319632=319631=319632=diff
==
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Sun Dec  3 08:04:07 2017
@@ -583,5 +583,46 @@ TEST(ImportExpr, ImportCXXPseudoDestruct
  callExpr(has(cxxPseudoDestructorExpr();
 }
 
+TEST(ImportDecl, ImportUsingDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "namespace foo { int bar; }"
+  "int declToImport(){ using foo::bar; }",
+  Lang_CXX, "", Lang_CXX, Verifier,
+  functionDecl(
+has(
+  compoundStmt(
+has(
+  declStmt(
+has(
+  usingDecl();
+}
+
+/// \brief Matches shadow declarations introduced into a scope by a
+///(resolved) using declaration.
+///
+/// Given
+/// \code
+///   namespace n { int f; }
+///   namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+///   matches \code f \endcode
+const internal::VariadicDynCastAllOfMatcher usingShadowDecl;
+
+TEST(ImportDecl, ImportUsingShadowDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "namespace foo { int bar; }"
+  "namespace declToImport { using foo::bar; }",
+  Lang_CXX, "", Lang_CXX, Verifier,
+  namespaceDecl(
+has(
+  usingShadowDecl();
+}
+
 } // end namespace ast_matchers
 } // end namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27181: [ASTImporter] Support for importing UsingDecl and UsingShadowDecl

2017-12-03 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hello Kareem,

While the functionality of this patch is already implemented in my already 
merged patch, I added your tests into the repo. Thank you!


https://reviews.llvm.org/D27181



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27181: [ASTImporter] Support for importing UsingDecl and UsingShadowDecl

2017-12-03 Thread Aleksei Sidorin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319632: [ASTImporter] Add unit tests for UsingDecl and 
UsingShadowDecl (authored by a.sidorin).

Changed prior to commit:
  https://reviews.llvm.org/D27181?vs=79488=125290#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27181

Files:
  cfe/trunk/unittests/AST/ASTImporterTest.cpp


Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp
@@ -583,5 +583,46 @@
  callExpr(has(cxxPseudoDestructorExpr();
 }
 
+TEST(ImportDecl, ImportUsingDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "namespace foo { int bar; }"
+  "int declToImport(){ using foo::bar; }",
+  Lang_CXX, "", Lang_CXX, Verifier,
+  functionDecl(
+has(
+  compoundStmt(
+has(
+  declStmt(
+has(
+  usingDecl();
+}
+
+/// \brief Matches shadow declarations introduced into a scope by a
+///(resolved) using declaration.
+///
+/// Given
+/// \code
+///   namespace n { int f; }
+///   namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+///   matches \code f \endcode
+const internal::VariadicDynCastAllOfMatcher usingShadowDecl;
+
+TEST(ImportDecl, ImportUsingShadowDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "namespace foo { int bar; }"
+  "namespace declToImport { using foo::bar; }",
+  Lang_CXX, "", Lang_CXX, Verifier,
+  namespaceDecl(
+has(
+  usingShadowDecl();
+}
+
 } // end namespace ast_matchers
 } // end namespace clang


Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp
@@ -583,5 +583,46 @@
  callExpr(has(cxxPseudoDestructorExpr();
 }
 
+TEST(ImportDecl, ImportUsingDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "namespace foo { int bar; }"
+  "int declToImport(){ using foo::bar; }",
+  Lang_CXX, "", Lang_CXX, Verifier,
+  functionDecl(
+has(
+  compoundStmt(
+has(
+  declStmt(
+has(
+  usingDecl();
+}
+
+/// \brief Matches shadow declarations introduced into a scope by a
+///(resolved) using declaration.
+///
+/// Given
+/// \code
+///   namespace n { int f; }
+///   namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+///   matches \code f \endcode
+const internal::VariadicDynCastAllOfMatcher usingShadowDecl;
+
+TEST(ImportDecl, ImportUsingShadowDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "namespace foo { int bar; }"
+  "namespace declToImport { using foo::bar; }",
+  Lang_CXX, "", Lang_CXX, Verifier,
+  namespaceDecl(
+has(
+  usingShadowDecl();
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40225: Add -std=c17 as a flag

2017-12-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping


https://reviews.llvm.org/D40225



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39665: Support __has_c_attribute

2017-12-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping


https://reviews.llvm.org/D39665



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40737: [clang-tidy] Resubmit hicpp-multiway-paths-covered without breaking test

2017-12-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I would like to see the large test case added back in -- it was demonstrating a 
real problem with the code and it would be good to ensure we don't regress that 
behavior again in the future.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40737



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40671: [clang-tidy] Support specific checks for NOLINT directive

2017-12-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:299
+size_t BracketIndex = NolintIndex + NolintMacro.size();
+// Check if the specific checks are specified in brackets
+if (BracketIndex < Line.size() && Line[BracketIndex] == '(') {

Comments should be complete sentences, including punctuation (here and 
elsewhere).



Comment at: docs/ReleaseNotes.rst:259-260
 
+- Added an ability to specify in parentheses the list of checks to suppress 
for the ``NOLINT`` 
+  and ``NOLINTNEXTLINE`` comments.
+

How about: "Added the ability to suppress specific checks (or all checks) in a 
NOLINT or NOLINTNEXTLINE comment."?



Comment at: docs/clang-tidy/index.rst:253
 
+Generally, there is no need to suppress :program:`clang-tidy` diagnostics. If
+there are false positives, either a bug should be reported or the code should 
be

I don't agree with that initial statement's use of "generally" -- checks that 
are chatty live in clang-tidy, as are checks for various coding standards 
(which commonly have a  deviation mechanism). Also, I don't think we should 
encourage users to unconditionally report false positives as bugs; many of the 
coding standard related checks provide true positives that are annoying and 
users may want to deviate in certain circumstances (like CERT's rule banning 
use of `rand()` or `system()`). I would reword this to:
```
While clang-tidy diagnostics are intended to call out code that does not adhere 
to a coding standard, or is otherwise problematic in some way, there are times 
when it is more appropriate to silence the diagnostic instead of changing the 
semantics of the code. In such circumstances, the NOLINT or NOLINTNEXTLINE 
comments can be used to silence the diagnostic. For example:
```
I would also describe the comment syntax more formally as (my markdown may be 
incorrect, you should ensure this renders sensibly), with surrounding prose:
```
*lint-comment:*
  *lint-command* *lint-args~opt~*
  
*lint-args:*
  `(` *check-name-list* `)`

*check-name-list:*
  *check-name*
  *check-name-list* `,` *check-name*

*lint-command:*
  `NOLINT`
  `NOLINTNEXTLINE`
```
Specific to the prose mentioned above, you should document where the feature is 
tolerant to whitespace (can there be a space between NOLINT and the parens, 
what about inside the parens, how about after or before commas, etc).



Comment at: docs/clang-tidy/index.rst:270
+// Skip only the specified diagnostics for the next line
+// NOLINTNEXTLINE (google-explicit-constructor, google-runtime-int)
+Foo(bool param); 

Is the space before the `(` intended?


https://reviews.llvm.org/D40671



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40580: [clang-tidy] Adding Fuchsia checker for multiple inheritance

2017-12-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/fuchsia/MultipleInheritanceCheck.cpp:60
+  // To be an interface, all base classes must be interfaces as well.
+  for (const auto  : Node->bases()) {
+const auto *Ty = I.getType()->getAs();

juliehockett wrote:
> aaron.ballman wrote:
> > What about virtual bases (`Node->vbases()`)? This would also be worth some 
> > test cases.
> Added test cases for virtual, but aren't virtual bases also included in 
> `bases()`?
No, they are separate in `CXXRecordDecl`.



Comment at: test/clang-tidy/fuchsia-multiple-inheritance.cpp:48
+};
+
+// Inherits from multiple concrete classes.

The virtual base test cases I was thinking of were:
```
struct Base { virtual void foo() = 0; };
struct V1 : virtual Base {};
struct V2 : virtual Base {};
struct D : V1, V2 {}; // Should be fine
---
struct Base { virtual void foo(); };
struct V1 : virtual Base {};
struct V2 : virtual Base {};
struct D : V1, V2 {}; // Should be fine (there's only one concrete base)?
---
struct Base {};
struct V1 : virtual Base { virtual void f(); }
struct V2 : virtual Base { virtual void g(); }
struct D : V1, V2 {}; // Not okay
---
struct Base {};
struct V1 : virtual Base { virtual void f() = 0; }
struct V2 : virtual Base { virtual void g() = 0; }
struct D : V1, V2 {}; // Okay
---
struct Base { virtual void f(); };
struct V1 : virtual Base { virtual void f(); }
struct V2 : virtual base { virtual void g() = 0; }
struct D : V1, V2 {}; // Should be okay (V1::f() overrides Base::f() which is 
only inherited once)?
```


https://reviews.llvm.org/D40580



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40715: [analyser] different.LabelInsideSwitch checker implementation

2017-12-03 Thread Kirill Romanenkov via Phabricator via cfe-commits
kromanenkov added a comment.

A few comments.




Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:19
+if (S.second)
+  return S;
+

Maybe I miss something, but do not we return StringRef to temporary string 
going out of scope here? Same below.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:24
+
+  class WalkAST : public ConstStmtVisitor {
+const CheckerBase *Checker;

Do you consider using ASTMatchers like in NumberObjectConversionChecker instead 
of manually traversing the AST?



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:59
+BR.EmitBasicReport(AC->getDecl(), Checker, "Labeled statement inside 
switch",
+   categories::LogicError, OS.str(), Loc, Sr);
+  }

a.sidorin wrote:
> raw_svector_ostream is always synchronized with the string it prints to so we 
> can just pass the message string instead of calling .str().
You could use S->getSourceRange() instead of Sr, as llvm::ArrayRef in 
EmitBasicReport() could be constructed even from the 0 consecutively elements.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:80
+  MinSize = ExpSize;
+}
+

Maybe so?
size_t MinSize = std::min(StrSize, ExpSize);
size_t SizeDelta = std::labs(StrSize, ExpSize);


Repository:
  rC Clang

https://reviews.llvm.org/D40715



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40715: [analyser] different.LabelInsideSwitch checker implementation

2017-12-03 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hello Alexey,

Thank you for the patch. I have made a preliminary review and will add some 
other reviewers. You can find my comments inline.




Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:1
+#include "clang/AST/StmtVisitor.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"

License header and checker descriptions are missed here. You can take a look at 
any other checker to find how it should be filled.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:10
+namespace {
+  class LabelInsideSwitchChecker : public Checker< check::ASTCodeBody > {
+  public:

Spaces in template arguments should be removed.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:12
+  public:
+void checkASTCodeBody(const Decl *D, AnalysisManager , BugReporter 
) const;
+  };

LLVM Coding Standard requires variables to start with capital letter: 'Mgr'. 
Please change such names here and below.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:15
+
+  static std::pair Suggest(const StringRef , StringRef 
Exp);
+  static std::pair SuggestTypoFix(const StringRef ) {

We usually pass StringRef by value, not by reference. Same below.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:16
+  static std::pair Suggest(const StringRef , StringRef 
Exp);
+  static std::pair SuggestTypoFix(const StringRef ) {
+const auto S = Suggest(Str, "default");

LLVM Coding Standard requires method names to start with small letter.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:33
+
+// Statement visitor methods.
+void VisitChildren(const Stmt *S, bool InSwitch) {

Obvious comment. I think it is better to remove it.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:47
+
+SmallString<256> SBuf;
+llvm::raw_svector_ostream OS(SBuf);

1. The longest string we can get here is "label inside switch (did you mean 
'default'?)". It is 46 char long so we can reduce the allocation size to 48 or 
64.
2. Should we rename the variable to "Message"?



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:59
+BR.EmitBasicReport(AC->getDecl(), Checker, "Labeled statement inside 
switch",
+   categories::LogicError, OS.str(), Loc, Sr);
+  }

raw_svector_ostream is always synchronized with the string it prints to so we 
can just pass the message string instead of calling .str().



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:65
+
+  std::pair Suggest(const StringRef , StringRef Exp) {
+const size_t StrSize = Str.size();

Seems like you are trying to implement some kind of  "similarity" metric. 
Consider using `StringRef::edit_distance()` instead. I guess, in your case it 
will give you much more freedom to vary different match parameters. For 
example, it can consider replacements.
Also, I think it's better to rename this function into something like 
"areStringsSimilar()".



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:84
+if (SizeDelta > 1)
+return std::make_pair("", false);
+

1. The indent looks broken here. You can use clang-format tool to automatically 
make your code formatted as needed.
2. How about just returning StringRef? We can return empty StringRef (`return 
StringRef()`) if no matches found and return a non-empty value if match was 
found.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:110
+
+void LabelInsideSwitchChecker::checkASTCodeBody(const Decl *D, AnalysisManager 
, BugReporter ) const {
+  WalkAST walker(this, BR, mgr.getAnalysisDeclContext(D));

This line exceeds 80-char limit. Please split it.



Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:115
+
+namespace clang {
+  namespace ento {

You can write just `void ento::registerLabelInsideSwitchChecker(CheckerManager 
) { 



Comment at: test/Analysis/label-inside-switch.c:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.LabelInsideSwitch 
-w -verify %s
+

Not sure if we need to enable 'core' while testing path-insensitive checkers. 
Artem?



Comment at: test/Analysis/label-inside-switch.c:5
+  int res = 0;
+  switch(count) {
+  case 1:

Space after `switch`. Same below


Repository:
  rC Clang

https://reviews.llvm.org/D40715



___
cfe-commits 

[PATCH] D40775: [libcxx] Add underscores to win32 locale headers.

2017-12-03 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

Avoid possible collisions with macros.


Repository:
  rCXX libc++

https://reviews.llvm.org/D40775

Files:
  include/support/win32/locale_win32.h
  src/support/win32/locale_win32.cpp

Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -16,9 +16,9 @@
 using std::__libcpp_locale_guard;
 
 // FIXME: base currently unused. Needs manual work to construct the new locale
-locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
+locale_t newlocale( int __mask, const char * __locale, locale_t /*__base*/ )
 {
-return {_create_locale( LC_ALL, locale ), locale};
+return {_create_locale( LC_ALL, __locale ), __locale};
 }
 
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
@@ -32,90 +32,90 @@
 }
 
 
-lconv *localeconv_l( locale_t loc )
+lconv *localeconv_l( locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
+__libcpp_locale_guard __current(__loc);
 return localeconv();
 }
-size_t mbrlen_l( const char *__restrict s, size_t n,
- mbstate_t *__restrict ps, locale_t loc )
+size_t mbrlen_l( const char *__restrict __s, size_t __n,
+ mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrlen( s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrlen( __s, __n, __ps );
 }
-size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
-size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsrtowcs( dst, src, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsrtowcs( __dst, __src, __len, __ps );
 }
-size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
-  locale_t loc )
+size_t wcrtomb_l( char *__restrict __s, wchar_t __wc, mbstate_t *__restrict __ps,
+  locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcrtomb( s, wc, ps );
+__libcpp_locale_guard __current(__loc);
+return wcrtomb( __s, __wc, __ps );
 }
-size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
-  size_t n, mbstate_t *__restrict ps, locale_t loc )
+size_t mbrtowc_l( wchar_t *__restrict __pwc, const char *__restrict __s,
+  size_t __n, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrtowc( pwc, s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrtowc( __pwc, __s, __n, __ps );
 }
-size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
- size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsnrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+ size_t __nms, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsnrtowcs( dst, src, nms, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsnrtowcs( __dst, __src, __nms, __len, __ps );
 }
-size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
- size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t wcsnrtombs_l( char *__restrict __dst, const wchar_t **__restrict __src,
+ size_t __nwc, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcsnrtombs( dst, src, nwc, len, ps );
+__libcpp_locale_guard __current(__loc);
+return wcsnrtombs( __dst, __src, __nwc, __len, __ps );
 }
-wint_t btowc_l( int c, locale_t loc )
+wint_t btowc_l( int __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return btowc( c );
+__libcpp_locale_guard __current(__loc);
+return btowc( __c );
 }
-int wctob_l( wint_t c, locale_t loc )
+int wctob_l( wint_t __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wctob( c );
+__libcpp_locale_guard __current(__loc);
+return wctob( __c );
 }
 
-int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
+int snprintf_l(char *__ret, size_t __n, locale_t __loc, const char *__format, ...)
 {
-__libcpp_locale_guard __current(loc);
+__libcpp_locale_guard __current(__loc);
 va_list ap;
-va_start( ap, format );
-int result = vsnprintf( ret, n, format, ap );
+va_start( ap, __format );
+int result = vsnprintf( __ret, __n, __format, ap );
 va_end(ap);
 return result;
 }
 
-int asprintf_l( char **ret, locale_t loc, const char *format, ... )
+int asprintf_l( char **__ret, locale_t __loc, const char 

[PATCH] D39284: Allow conditions to be decomposed with structured bindings

2017-12-03 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:712-720
+  Diag(Decomp.getLSquareLoc(), [&] {
+if (getLangOpts().CPlusPlus1z) {
+  if (D.getContext() == Declarator::ConditionContext)
+return diag::ext_decomp_decl_cond;
+  else
+return diag::warn_cxx14_compat_decomp_decl;
+} else

rsmith wrote:
> Using a lambda here seems like unwarranted complexity. A three-way ternary of 
> the form
> 
> ```
> !getLangOpts().CPlusPlus1z ? diag::ext_decomp_decl :
> D.getContext() == Declarator::ConditionContext ? diag::ext_decomp_decl_cond :
> diag::warn_cxx14_compat_decomp_decl
> ```
> 
> would be fine. Feel free to ignore clang-format if it wants to format it 
> stupidly.
The clang-formatted code actually looks good.



Comment at: test/Misc/warning-flags.c:19
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 

rsmith wrote:
> Please read and respect this rule :)
Do you know of some categories which can cover this kind of extensions?


Repository:
  rC Clang

https://reviews.llvm.org/D39284



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39284: Allow conditions to be decomposed with structured bindings

2017-12-03 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 125288.
lichray marked 3 inline comments as done.
lichray added a comment.

Rephrase warning message.


Repository:
  rC Clang

https://reviews.llvm.org/D39284

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/DeclSpec.h
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/Misc/warning-flags.c
  test/Parser/cxx1z-decomposition.cpp
  test/Parser/decomposed-condition.cpp
  test/SemaCXX/decomposed-condition.cpp

Index: test/SemaCXX/decomposed-condition.cpp
===
--- /dev/null
+++ test/SemaCXX/decomposed-condition.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -std=c++1z -w -verify %s
+
+struct X {
+  bool flag;
+  int data;
+  constexpr explicit operator bool() const {
+return flag;
+  }
+  constexpr operator int() const {
+return data;
+  }
+};
+
+namespace CondInIf {
+constexpr int f(X x) {
+  if (auto [ok, d] = x)
+return d + int(ok);
+  else
+return d * int(ok);
+  ok = {}; // expected-error {{use of undeclared identifier 'ok'}}
+  d = {};  // expected-error {{use of undeclared identifier 'd'}}
+}
+
+static_assert(f({true, 2}) == 3);
+static_assert(f({false, 2}) == 0);
+
+constexpr char g(char const ()[2]) {
+  if (auto &[a, b] = x)
+return a;
+  else
+return b;
+
+  if (auto [a, b] = x) // expected-error {{an array type is not allowed here}}
+;
+}
+
+static_assert(g("x") == 'x');
+} // namespace CondInIf
+
+namespace CondInSwitch {
+constexpr int f(int n) {
+  switch (X s = {true, n}; auto [ok, d] = s) {
+s = {};
+  case 0:
+return int(ok);
+  case 1:
+return d * 10;
+  case 2:
+return d * 40;
+  default:
+return 0;
+  }
+  ok = {}; // expected-error {{use of undeclared identifier 'ok'}}
+  d = {};  // expected-error {{use of undeclared identifier 'd'}}
+  s = {};  // expected-error {{use of undeclared identifier 's'}}
+}
+
+static_assert(f(0) == 1);
+static_assert(f(1) == 10);
+static_assert(f(2) == 80);
+} // namespace CondInSwitch
+
+namespace CondInWhile {
+constexpr int f(int n) {
+  int m = 1;
+  while (auto [ok, d] = X{n > 1, n}) {
+m *= d;
+--n;
+  }
+  return m;
+  return ok; // expected-error {{use of undeclared identifier 'ok'}}
+}
+
+static_assert(f(0) == 1);
+static_assert(f(1) == 1);
+static_assert(f(4) == 24);
+} // namespace CondInWhile
+
+namespace CondInFor {
+constexpr int f(int n) {
+  int a = 1, b = 1;
+  for (X x = {true, n}; auto &[ok, d] = x; --d) {
+if (d < 2)
+  ok = false;
+else {
+  int x = b;
+  b += a;
+  a = x;
+}
+  }
+  return b;
+  return d; // expected-error {{use of undeclared identifier 'd'}}
+}
+
+static_assert(f(0) == 1);
+static_assert(f(1) == 1);
+static_assert(f(2) == 2);
+static_assert(f(5) == 8);
+} // namespace CondInFor
Index: test/Parser/decomposed-condition.cpp
===
--- /dev/null
+++ test/Parser/decomposed-condition.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -std=c++1z %s -verify
+
+struct Na {
+  bool flag;
+  float data;
+};
+
+struct Rst {
+  bool flag;
+  float data;
+  explicit operator bool() const {
+return flag;
+  }
+};
+
+Rst f();
+Na g();
+
+namespace CondInIf {
+void h() {
+  if (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  if (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInIf
+
+namespace CondInWhile {
+void h() {
+  while (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  while (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInWhile
+
+namespace CondInFor {
+void h() {
+  for (; auto [ok, d] = f();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  for (; auto [ok, d] = g();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInFor
+
+struct IntegerLike {
+  bool flag;
+  float data;
+  operator int() const {
+return int(data);
+  }
+};
+
+namespace CondInSwitch {
+void h(IntegerLike x) {
+  switch (auto [ok, d] = x) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  switch (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{statement requires expression of integer type ('Na' invalid)}}
+;
+}
+} // namespace 

[PATCH] D40774: [libcxx] Fix intrinsics for MSVC

2017-12-03 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

The parameter was previously renamed but MSVC path was not updated.


https://reviews.llvm.org/D40774

Files:
  include/algorithm


Index: include/algorithm
===
--- include/algorithm
+++ include/algorithm
@@ -797,7 +797,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanForward(, mask))
+  if (_BitScanForward(, __x))
 return where;
   return 32;
 #endif
@@ -823,15 +823,15 @@
 // Returns zero if no set bit is found.
 #if defined(_LIBCPP_HAS_BITSCAN64)
 (defined(_M_AMD64) || defined(__x86_64__))
-  if (_BitScanForward64(, mask))
+  if (_BitScanForward64(, __x))
 return static_cast(where);
 #else
   // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
   // Scan the Low Word.
-  if (_BitScanForward(, static_cast(mask)))
+  if (_BitScanForward(, static_cast(__x)))
 return where;
   // Scan the High Word.
-  if (_BitScanForward(, static_cast(mask >> 32)))
+  if (_BitScanForward(, static_cast(__x >> 32)))
 return where + 32; // Create a bit offset from the LSB.
 #endif
   return 64;
@@ -849,7 +849,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanReverse(, mask))
+  if (_BitScanReverse(, __x))
 return 31 - where;
   return 32; // Undefined Behavior.
 #endif
@@ -874,14 +874,14 @@
 // BitScanReverse scans from MSB to LSB for first set bit.
 // Returns 0 if no set bit is found.
 #if defined(_LIBCPP_HAS_BITSCAN64)
-  if (_BitScanReverse64(, mask))
+  if (_BitScanReverse64(, __x))
 return static_cast(63 - where);
 #else
   // Scan the high 32 bits.
-  if (_BitScanReverse(, static_cast(mask >> 32)))
+  if (_BitScanReverse(, static_cast(__x >> 32)))
 return 63 - (where + 32); // Create a bit offset from the MSB.
   // Scan the low 32 bits.
-  if (_BitScanReverse(, static_cast(mask)))
+  if (_BitScanReverse(, static_cast(__x)))
 return 63 - where;
 #endif
   return 64; // Undefined Behavior.


Index: include/algorithm
===
--- include/algorithm
+++ include/algorithm
@@ -797,7 +797,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanForward(, mask))
+  if (_BitScanForward(, __x))
 return where;
   return 32;
 #endif
@@ -823,15 +823,15 @@
 // Returns zero if no set bit is found.
 #if defined(_LIBCPP_HAS_BITSCAN64)
 (defined(_M_AMD64) || defined(__x86_64__))
-  if (_BitScanForward64(, mask))
+  if (_BitScanForward64(, __x))
 return static_cast(where);
 #else
   // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
   // Scan the Low Word.
-  if (_BitScanForward(, static_cast(mask)))
+  if (_BitScanForward(, static_cast(__x)))
 return where;
   // Scan the High Word.
-  if (_BitScanForward(, static_cast(mask >> 32)))
+  if (_BitScanForward(, static_cast(__x >> 32)))
 return where + 32; // Create a bit offset from the LSB.
 #endif
   return 64;
@@ -849,7 +849,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanReverse(, mask))
+  if (_BitScanReverse(, __x))
 return 31 - where;
   return 32; // Undefined Behavior.
 #endif
@@ -874,14 +874,14 @@
 // BitScanReverse scans from MSB to LSB for first set bit.
 // Returns 0 if no set bit is found.
 #if defined(_LIBCPP_HAS_BITSCAN64)
-  if (_BitScanReverse64(, mask))
+  if (_BitScanReverse64(, __x))
 return static_cast(63 - where);
 #else
   // Scan the high 32 bits.
-  if (_BitScanReverse(, static_cast(mask >> 32)))
+  if (_BitScanReverse(, static_cast(__x >> 32)))
 return 63 - (where + 32); // Create a bit offset from the MSB.
   // Scan the low 32 bits.
-  if (_BitScanReverse(, static_cast(mask)))
+  if (_BitScanReverse(, static_cast(__x)))
 return 63 - where;
 #endif
   return 64; // Undefined Behavior.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r319631 - Corrected a typo in the building libc++ docs

2017-12-03 Thread Hamza Sood via cfe-commits
Author: hamzasood
Date: Sun Dec  3 02:18:35 2017
New Revision: 319631

URL: http://llvm.org/viewvc/llvm-project?rev=319631=rev
Log:
Corrected a typo in the building libc++ docs

Modified:
libcxx/trunk/docs/BuildingLibcxx.rst

Modified: libcxx/trunk/docs/BuildingLibcxx.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/BuildingLibcxx.rst?rev=319631=319630=319631=diff
==
--- libcxx/trunk/docs/BuildingLibcxx.rst (original)
+++ libcxx/trunk/docs/BuildingLibcxx.rst Sun Dec  3 02:18:35 2017
@@ -130,7 +130,7 @@ just specify a toolset.
   -DCMAKE_SYSTEM_NAME=Windows  
   ^
   -DCMAKE_C_COMPILER=clang-cl  
   ^
   -DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 
--target=i686--windows"   ^
-  -DCMAKE_CXX_COMPILER=clang-c 
   ^
+  -DCMAKE_CXX_COMPILER=clang-cl
^
   -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 
--target=i686--windows" ^
   -DLLVM_PATH=/path/to/llvm/tree   
   ^
   -DLIBCXX_ENABLE_SHARED=YES   
   ^


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits