• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // Check that format functions are marked [[nodiscard]] as a conforming extension
10 
11 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // UNSUPPORTED: no-filesystem, no-localization, no-tzdb
13 
14 // XFAIL: libcpp-has-no-experimental-tzdb
15 // XFAIL: availability-tzdb-missing
16 
17 // <chrono>
18 
19 #include <chrono>
20 
21 #include "test_macros.h"
22 
23 // These types have "private" constructors.
test(std::chrono::time_zone tz,std::chrono::time_zone_link link,std::chrono::leap_second leap)24 void test(std::chrono::time_zone tz, std::chrono::time_zone_link link, std::chrono::leap_second leap) {
25   std::chrono::tzdb_list& list = std::chrono::get_tzdb_list();
26   list.front();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27   list.begin();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
28   list.end();    // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
29   list.cbegin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
30   list.cend();   // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
31 
32   {
33     const std::chrono::tzdb& t = list.front();
34     t.locate_zone("name"); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
35     t.current_zone();      // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
36   }
37 
38   namespace crno = std::chrono;
39   crno::get_tzdb_list();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
40   crno::get_tzdb();       // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
41   crno::locate_zone("n"); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
42   crno::current_zone();   // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
43   crno::remote_version(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
44 
45   {
46     std::chrono::sys_seconds s{};
47     std::chrono::local_seconds l{};
48     std::chrono::choose z = std::chrono::choose::earliest;
49     tz.name();           // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
50     tz.get_info(s);      // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
51     tz.get_info(l);      // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
52     tz.to_sys(l);        // not nodiscard
53     tz.to_sys(l, z);     // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
54     operator==(tz, tz);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
55     operator<=>(tz, tz); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
56   }
57 
58   {
59     link.name();   // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
60     link.target(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
61     // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
62     operator==(link, link);
63     // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
64     operator<=>(link, link);
65   }
66 
67   {
68     leap.date();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
69     leap.value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
70   }
71 
72   {
73     using t = std::chrono::zoned_traits<const std::chrono::time_zone*>;
74     t::default_zone();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
75     t::locate_zone(""); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
76   }
77 
78   {
79     std::chrono::zoned_time<std::chrono::seconds> zt;
80 
81     // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
82     static_cast<std::chrono::sys_seconds>(zt);
83     // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
84     static_cast<std::chrono::local_seconds>(zt);
85 
86     zt.get_time_zone();  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
87     zt.get_local_time(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
88     zt.get_sys_time();   // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
89     zt.get_info();       // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
90   }
91 }
92