# Constexpr デバッガー

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/ja-jp/help/clion/llms.txt).

Constexpr デバッガーは、特に  `constexpr`  および  `consteval`  コードにおけるコンパイル時の評価に関するインサイトを提供します。 これにより、コンパイラーの世界に留まり、評価中に何が起こっているかを正確に把握できます。

[Video](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_overview.mp4)

現在、Constexpr デバッガーで実行できる操作は次のとおりです。

* `static_assert(...)` または `constexpr` 宣言子の横にある デバッグ ボタンをクリックしてガターからステップバイステップのデバッグを開始し、評価方法や失敗した理由を確認します。

* 通常のデバッガーと [同じアクション](stepping-through-the-program.html)（ ステップイン や ステップオーバー など）を使用します。 さらに、コンパイル時の逆ステップ実行機能である 後退 も使用できます。

* コンパイラーが認識する内容（呼び出しスタック、ローカル、最後の戻り値、現在のインスタンス化のテンプレート引数）を確認します。

* 変数の上にマウスを移動してその値を表示するか、 式の評価 を使用するか、呼び出しスタックからソースコードに移動します。

* 定数評価がいつ、なぜ発生したかを特定できない場合は、コンテキスト全体をインスペクションします。

## 主なデバッグ機能

次のセクションでは、  `constexpr`  コードをデバッグするときに実行できる重要なアクションの概要を示します。

Procedure: デバッグを開始する

コード例として、コンパイル時のフィボナッチキャッシュの実装を考えてみましょう。

```CPLUSPLUS
#include <array>

template<std::size_t N>
struct FibCache {
    std::array<int, N + 1> memo{};

    constexpr FibCache() {
        memo[0] = 0; memo[1] = 1;
        for (std::size_t i = 2; i <= N; ++i)
            memo[i] = memo[i - 1] + memo[i - 2];
    }

    constexpr int operator()(int n) const { return memo[n]; }
};

constexpr int get_fibonacci(int n) {
    FibCache<8> cache;
    auto result = cache(n);
    return result;
}

constexpr int k = get_fibonacci(6);
static_assert(get_fibonacci(6) == 8, "ok");
            
```

1. Click the ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.actions.startDebugger.png) icon next to the  `constexpr`  declarator or  `static_assert`  to start debugging:

![デバッグを開始する](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_start.png)

2. Use the standard   ステップイン   or   ステップオーバー   debugger actions to evaluate expressions:

![ステップイン](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_basic_actions.png)

3. Use   後退   to navigate back through each step of the compile-time evaluation:

![後退する](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_step_back.png)

4. 状態をインスペクションします。

* Hover over `this->memo` in the editor to watch how the array fills during construction: ![メモをインスペクションする](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_memo.png)

* Evaluate expressions or types by pressing `Alt+F8` (Windows), `⌥ F8` (macOS), `⌥ F8` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ L` (macOS System Shortcuts), `Alt+F8` (XWin), `Alt+Shift+8` (GNOME), `Alt+Shift+8` (KDE), `Alt+F8` (Emacs), `Alt+F8` (Sublime Text), `⌥ F8` (Sublime Text (macOS)), `⌥ F8` (Xcode), `Shift+F9` (Visual Studio), `⇧ F9` (Visual Studio (macOS)), `Shift+F9` (ReSharper), `⇧ F9` (ReSharper (macOS)), `Alt+F8` (QtCreator), `⌥ F8` (QtCreator (macOS)), `Ctrl+F9` (NetBeans), `Ctrl+U` (Eclipse), `⌘ U` (Eclipse (macOS)): ![式の評価](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_evaluate.png)

* Check the `スレッド & 変数` pane to see `this` , locals like `i` , and recent returns: ![変数のインスペクション](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_variables.png)

* Use the `フレーム` pane to see the call stack and navigate to the source code: ![コールスタックをインスペクションする](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_call_stack.png)

5. Check the result in the  `スレッド & 変数`  pane after the constructor has precomputed all the Fibonacci numbers:

![結果のインスペクション](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_result.png)

Procedure: コンパイル時のエラーを診断して修正する

* たとえば、コードロジックの誤りなどにより評価が失敗した場合、CLion はエラーをハイライト表示します。 When you hover over it, a popup appears with the problem explanation: ![エラーポップアップ](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_error_popup.png) エラーの原因と発生ステップが不明な場合は、 失敗するまで評価を実行する をクリックしてデバッグしてください。 Constexpr デバッガーは失敗した評価箇所で停止し、エラーメッセージとコンテキストを表示します。

* コンパイル時に式を評価できない場合（たとえば、非 constexpr 関数が呼び出された場合）、CLion はエディターとデバッグの両方でエラーをハイライトします。 ![非 constexpr 評価](https://resources.jetbrains.com/help/img/idea/2026.3/cl_constexpr_debugger_non_constexpr.png)

## 制限

* ブレークポイントと Cursor まで実行 /Cursor まで強制実行 は constexpr 評価ではサポートされていません。

* 一部の構文はまだ constexpr 評価ツールでサポートされていません。 進捗状況の確認や関連する問題への投票は [YouTrack](https://jb.gg/cpp_constexpr_evaluation) で行えます。

## See also

### 関連

[デバッグ](debugging-code.html) [デバッグセッションを開始/一時停止/停止する](starting-the-debugger-session.html) [ステップ実行](stepping-through-the-program.html) [中断されたプログラムを調べる](examining-suspended-program.html)

