Fast Constraint Synthesis for C++ Function Templates
Shuo Ding, Qirun Zhang
摘要
C++ templates are a powerful feature for generic programming and compile-time computations, but C++ compilers often emit overly verbose template error messages. Even short error messages often involve unnecessary and confusing implementation details, which are difficult for developers to read and understand. To address this problem, C++20 introduced constraints and concepts, which impose requirements on template parameters. The new features can define clearer interfaces for templates and can improve compiler diagnostics. However, manually specifying template constraints can still be non-trivial, which becomes even more challenging when working with legacy C++ projects or with frequent code changes.
This paper bridges the gap and proposes an automatic approach to synthesizing constraints for C++ function templates. We utilize a lightweight static analysis to analyze the usage patterns within the template body and summarize them into constraints for each type parameter of the template. The analysis is inter-procedural and uses disjunctions of constraints to model function overloading. We have implemented our approach based on the Clang frontend and evaluated it on two C++ libraries chosen separately from two popular library sets: algorithm from the Standard Template Library (STL) and special_functions from the Boost library, both of which extensively use templates. Our tool can process over 110k lines of C++ code in less than 1.5 seconds and synthesize non-trivial constraints for 30%-40% of the function templates. The constraints synthesized for algorithm align well with the standard documentation, and on average, the synthesized constraints can reduce error message lengths by 56.6% for algorithm and 63.8% for special_functions.
问问这篇 Paper
智能体会读完全文。
Lune 把这篇 Paper 索引到了每一个公式,引用它的顶会 Paper 也一样。你提问,回答直接引用原文。
它引用的顶会 Paper5
- Fuzzing deep-learning libraries via automated relational API inferenceYinlin Deng, Chenyuan Yang, Anjiang Wei, Lingming ZhangFSE 2022 · 被引用 83 次
- Static Inference Meets Deep learning: A Hybrid Type Inference Approach for PythonYun Peng, Cuiyun Gao, Zongjie Li, Bowei Gao 等ICSE 2022 · 被引用 48 次
- Making pointer analysis more precise by unleashing the power of selective context sensitivityTian Tan, Yue Li, Xiaoxing Ma, Chang Xu 等OOPSLA 2021 · 被引用 39 次
- Return of CFA: call-site sensitivity can be superior to object sensitivity even for object-oriented programsMinseok Jeon, Hakjoo OhPOPL 2022 · 被引用 15 次
- Complexity-guided container replacement synthesisChengpeng Wang, Peisen Yao, Wensheng Tang, Qingkai Shi 等OOPSLA 2022 · 被引用 11 次
相关 Paper
- Recursive Program Synthesis using ParamorphismsQiantan Hong, Alex AikenPLDI 2024 · 被引用 7 次
- Counterexample-Guided Inference of Modular SpecificationsWilliam T. Hallahan, Ranjit Jhala, Ruzica PiskacOOPSLA 2025 · 被引用 1 次
- Synthesizing SpecificationsKanghee Park, Loris D'Antoni, Thomas W. RepsOOPSLA 2023 · 被引用 9 次
- The raise of machine learning hyperparameter constraints in Python codeIngkarat Rak-amnouykit, Ana L. Milanova, Guillaume Baudart, Martin Hirzel 等ISSTA 2022 · 被引用 1 次
- AutoDSL: Automated domain-specific language design for structural representation of procedures with constraintsYu-Zhe Shi, Haofei Hou, Zhangqian Bi, Fanxu Meng 等ACL 2024
