1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65

base / types / pass_key_nocompile.nc [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a no-compile test suite.
// http://dev.chromium.org/developers/testing/no-compile-tests

#include "base/types/pass_key.h"

#include <utility>

namespace base {

class Manager;

// May not be created without a PassKey.
class Restricted {
 public:
  Restricted(PassKey<Manager>) {}
};

void Secret(PassKey<Manager>) {}

void CannotConstructFieldFromTemporaryPassKey() {
  class NotAManager {
   public:
    NotAManager() : restricted_(PassKey<Manager>()) {}  // expected-error {{calling a private constructor of class 'base::PassKey<base::Manager>'}}

   private:
    Restricted restricted_;
  };
}

void CannotConstructFieldFromImplicitPassKey() {
  class NotAManager {
   public:
    NotAManager() : restricted_({}) {}  // expected-error {{calling a private constructor of class 'base::PassKey<base::Manager>'}}

   private:
    Restricted restricted_;
  };
}

void CannotConstructTemporaryPassKey() {
  Secret(PassKey<Manager>());  // expected-error {{calling a private constructor of class 'base::PassKey<base::Manager>'}}
}

void CannotConstructPassKeyImplicitly() {
  Secret({});  // expected-error {{calling a private constructor of class 'base::PassKey<base::Manager>'}}
}

void CannotConstructNamedPassKey() {
  PassKey<Manager> key {};  // expected-error {{calling a private constructor of class 'base::PassKey<base::Manager>'}}
  Secret(key);
}

void CannotCopyNonCopyablePassKey(NonCopyablePassKey<Manager> key) {
  CannotCopyNonCopyablePassKey(key);  // expected-error {{call to deleted constructor of 'NonCopyablePassKey<Manager>'}}
}

void CannotMoveNonCopyablePassKey(NonCopyablePassKey<Manager> key) {
  CannotMoveNonCopyablePassKey(std::move(key));  // expected-error {{call to deleted constructor of 'NonCopyablePassKey<Manager>'}}
}

}  // namespace base