{"status":"ok","message-type":"work","message-version":"1.0.0","message":{"indexed":{"date-parts":[[2025,10,10]],"date-time":"2025-10-10T01:08:07Z","timestamp":1760058487666,"version":"build-2065373602"},"reference-count":61,"publisher":"Association for Computing Machinery (ACM)","issue":"OOPSLA1","license":[{"start":{"date-parts":[[2025,4,9]],"date-time":"2025-04-09T00:00:00Z","timestamp":1744156800000},"content-version":"vor","delay-in-days":0,"URL":"https:\/\/creativecommons.org\/licenses\/by\/4.0\/"}],"funder":[{"DOI":"10.13039\/100000001","name":"National Science Foundation","doi-asserted-by":"publisher","award":["2237440, 2114627"],"award-info":[{"award-number":["2237440, 2114627"]}],"id":[{"id":"10.13039\/100000001","id-type":"DOI","asserted-by":"publisher"}]},{"DOI":"10.13039\/100000185","name":"Defense Advanced Research Projects Agency","doi-asserted-by":"publisher","award":["N66001-21-C-4024"],"award-info":[{"award-number":["N66001-21-C-4024"]}],"id":[{"id":"10.13039\/100000185","id-type":"DOI","asserted-by":"publisher"}]}],"content-domain":{"domain":["dl.acm.org"],"crossmark-restriction":true},"short-container-title":["Proc. ACM Program. Lang."],"published-print":{"date-parts":[[2025,4,9]]},"abstract":"<jats:p>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.\n \n \n \n\n \n \n \nThis 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.<\/jats:p>","DOI":"10.1145\/3720422","type":"journal-article","created":{"date-parts":[[2025,4,9]],"date-time":"2025-04-09T13:48:26Z","timestamp":1744206506000},"page":"225-252","update-policy":"https:\/\/doi.org\/10.1145\/crossmark-policy","source":"Crossref","is-referenced-by-count":0,"title":["Fast Constraint Synthesis for C++ Function Templates"],"prefix":"10.1145","volume":"9","author":[{"ORCID":"https:\/\/orcid.org\/0000-0003-0843-0729","authenticated-orcid":false,"given":"Shuo","family":"Ding","sequence":"first","affiliation":[{"name":"Georgia Institute of Technology, Atlanta, USA"}]},{"ORCID":"https:\/\/orcid.org\/0000-0001-5367-9377","authenticated-orcid":false,"given":"Qirun","family":"Zhang","sequence":"additional","affiliation":[{"name":"Georgia Institute of Technology, Atlanta, USA"}]}],"member":"320","published-online":{"date-parts":[[2025,4,9]]},"reference":[{"key":"e_1_2_1_1_1","doi-asserted-by":"publisher","DOI":"10.1145\/1993498.1993569"},{"key":"e_1_2_1_2_1","doi-asserted-by":"publisher","DOI":"10.1145\/2660193.2660203"},{"key":"e_1_2_1_3_1","doi-asserted-by":"publisher","DOI":"10.1007\/11531142_19"},{"key":"e_1_2_1_4_1","unstructured":"Wisnu Anggoro and John Torjo. 2015. Boost. Asio C++ Network Programming. Packt Publishing Ltd."},{"key":"e_1_2_1_5_1","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-642-39799-8_60"},{"key":"e_1_2_1_6_1","doi-asserted-by":"publisher","DOI":"10.1145\/1411318.1411324"},{"key":"e_1_2_1_7_1","doi-asserted-by":"publisher","DOI":"10.1145\/3314221.3314648"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_8_1","unstructured":"Cppreference. Accessed in April 2024. Class template argument deduction. https:\/\/en.cppreference.com\/w\/cpp\/language\/class_template_argument_deduction"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_9_1","unstructured":"Cppreference. Accessed in April 2024. CPP named requirements: LegacyInputIterator. https:\/\/en.cppreference.com\/w\/cpp\/named_req\/InputIterator"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_10_1","unstructured":"Cppreference. Accessed in April 2024. Named Requirements. https:\/\/en.cppreference.com\/w\/cpp\/named_req"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_11_1","unstructured":"Cppreference. Accessed in April 2024. SFINAE. https:\/\/en.cppreference.com\/w\/cpp\/language\/sfinae"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_12_1","unstructured":"Cppreference. Accessed in April 2024. Template argument deduction. https:\/\/en.cppreference.com\/w\/cpp\/language\/template_argument_deduction"},{"key":"e_1_2_1_13_1","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-030-81685-8_4"},{"key":"e_1_2_1_14_1","doi-asserted-by":"publisher","DOI":"10.1145\/3540250.3549085"},{"key":"e_1_2_1_15_1","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-031-44245-2_12"},{"key":"e_1_2_1_16_1","doi-asserted-by":"publisher","unstructured":"Shuo Ding and Qirun Zhang. 2025. Fast Constraint Synthesis for C++ Function Templates (Artifact). https:\/\/doi.org\/10.5281\/zenodo.14945421 10.5281\/zenodo.14945421","DOI":"10.5281\/zenodo.14945421"},{"key":"e_1_2_1_17_1","unstructured":"Lee Zhi Eng. 2016. Qt5 C++ GUI programming cookbook. Packt Publishing Ltd."},{"key":"e_1_2_1_18_1","doi-asserted-by":"publisher","DOI":"10.1145\/3009837.3009851"},{"key":"e_1_2_1_19_1","doi-asserted-by":"publisher","DOI":"10.1145\/1621607.1621613"},{"key":"e_1_2_1_20_1","doi-asserted-by":"publisher","DOI":"10.1016\/S0049-237X(98)80049-9"},{"key":"e_1_2_1_21_1","doi-asserted-by":"publisher","DOI":"10.1561\/2500000010"},{"key":"e_1_2_1_22_1","unstructured":"ISO. Accessed in January 2025. A Tour of CPP: Containers and Algorithms. https:\/\/isocpp.org\/files\/4-Tour-Algo-draft.pdf 117 pages."},{"key":"e_1_2_1_23_1","unstructured":"ISO. Accessed in October 2024. The Standard Definition of CPP. https:\/\/www.iso.org\/standard\/79358.html"},{"key":"e_1_2_1_24_1","doi-asserted-by":"publisher","DOI":"10.1145\/3498720"},{"key":"e_1_2_1_25_1","unstructured":"Nicolai M Josuttis. 2012. The C++ standard library: a tutorial and reference."},{"key":"e_1_2_1_26_1","doi-asserted-by":"publisher","DOI":"10.1145\/3158105"},{"key":"e_1_2_1_27_1","doi-asserted-by":"publisher","DOI":"10.1109\/CGO.2004.1281665"},{"key":"e_1_2_1_28_1","doi-asserted-by":"publisher","DOI":"10.1145\/1250734.1250783"},{"key":"e_1_2_1_29_1","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-642-22110-1_49"},{"key":"e_1_2_1_30_1","volume-title":"KIL: An Abstract Intermediate Language for Symbolic Execution and Test Generation of C++ Programs. 15.","author":"Li Guodong","year":"2012","unstructured":"Guodong Li, Indradeep Ghosh, and Sreeranga P Rajan. 2012. KIL: An Abstract Intermediate Language for Symbolic Execution and Test Generation of C++ Programs. 15."},{"key":"e_1_2_1_31_1","doi-asserted-by":"publisher","DOI":"10.1145\/3295739"},{"key":"e_1_2_1_32_1","doi-asserted-by":"publisher","DOI":"10.1145\/2644805"},{"key":"e_1_2_1_33_1","doi-asserted-by":"publisher","DOI":"10.1145\/1542476.1542485"},{"key":"e_1_2_1_34_1","unstructured":"LLVM. Accessed in April 2024. LLVM Language Reference Manual. https:\/\/llvm.org\/docs\/LangRef.html"},{"key":"e_1_2_1_35_1","doi-asserted-by":"publisher","DOI":"10.1002\/j.1538-7305.1956.tb03835.x"},{"key":"e_1_2_1_36_1","doi-asserted-by":"publisher","DOI":"10.1002\/STVR.1793"},{"key":"e_1_2_1_37_1","doi-asserted-by":"publisher","DOI":"10.1145\/2806886"},{"key":"e_1_2_1_38_1","doi-asserted-by":"publisher","DOI":"10.3102\/1076998619872761"},{"key":"e_1_2_1_39_1","doi-asserted-by":"publisher","DOI":"10.1145\/3510003.3510038"},{"key":"e_1_2_1_40_1","doi-asserted-by":"publisher","DOI":"10.2307\/2308219"},{"key":"e_1_2_1_41_1","doi-asserted-by":"publisher","DOI":"10.1080\/00029890.1955.11988710"},{"key":"e_1_2_1_42_1","doi-asserted-by":"publisher","DOI":"10.1145\/1250734.1250749"},{"key":"e_1_2_1_43_1","doi-asserted-by":"publisher","DOI":"10.1145\/1111037.1111064"},{"key":"e_1_2_1_44_1","doi-asserted-by":"publisher","DOI":"10.1145\/345099.345137"},{"key":"e_1_2_1_45_1","doi-asserted-by":"publisher","DOI":"10.1109\/TSE.2012.63"},{"key":"e_1_2_1_46_1","doi-asserted-by":"publisher","DOI":"10.1007\/11785477_19"},{"key":"e_1_2_1_47_1","doi-asserted-by":"publisher","DOI":"10.1145\/1706299.1706337"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_48_1","unstructured":"StackExchange. Accessed in April 2024. Generate the longest error message in CPP. https:\/\/codegolf.stackexchange.com\/a\/10470"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_49_1","unstructured":"StackOverflow. Accessed in April 2024. Compilation error for a binary search on the attributes. https:\/\/stackoverflow.com\/questions\/42604796\/compilation-error-for-a-binary-search-on-the-attributes"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_50_1","unstructured":"StackOverflow. Accessed in April 2024. Deciphering CPP template error messages. https:\/\/stackoverflow.com\/questions\/47980\/deciphering-c-template-error-messages"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_51_1","unstructured":"StackOverflow. Accessed in April 2024. How to improve compiler error messages when using CPP std::visit? https:\/\/stackoverflow.com\/questions\/72507596\/how-to-improve-compiler-error-messages-when-using-c-stdvisit"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_52_1","unstructured":"StackOverflow. Accessed in October 2024. Using stdsort in CPP with iterators and templates. https:\/\/stackoverflow.com\/questions\/59096297\/using-stdsort-in-c-with-iterators-and-templates"},{"volume-title":"A Tour of C++","author":"Stroustrup Bjarne","key":"e_1_2_1_53_1","unstructured":"Bjarne Stroustrup. 2022. A Tour of C++. Addison-Wesley Professional."},{"key":"e_1_2_1_54_1","doi-asserted-by":"publisher","DOI":"10.1145\/3485524"},{"volume-title":"Accessed","year":"2024","key":"e_1_2_1_55_1","unstructured":"Tumblr. Accessed in April 2024. The Grand CPP Error Explosion Competition. https:\/\/tgceec.tumblr.com\/"},{"key":"e_1_2_1_56_1","doi-asserted-by":"publisher","DOI":"10.1109\/TCAD.2005.855944"},{"key":"e_1_2_1_57_1","unstructured":"Todd L Veldhuizen. 2003. C++ templates are Turing complete. Indiana University."},{"key":"e_1_2_1_58_1","doi-asserted-by":"publisher","DOI":"10.1145\/3527312"},{"key":"e_1_2_1_59_1","doi-asserted-by":"publisher","DOI":"10.1109\/ICPC.2019.00052"},{"key":"e_1_2_1_60_1","doi-asserted-by":"publisher","DOI":"10.1145\/2950290.2950343"},{"key":"e_1_2_1_61_1","doi-asserted-by":"publisher","DOI":"10.1145\/3009837.3009848"}],"container-title":["Proceedings of the ACM on Programming Languages"],"original-title":[],"language":"en","link":[{"URL":"https:\/\/dl.acm.org\/doi\/10.1145\/3720422","content-type":"unspecified","content-version":"vor","intended-application":"text-mining"},{"URL":"https:\/\/dl.acm.org\/doi\/pdf\/10.1145\/3720422","content-type":"unspecified","content-version":"vor","intended-application":"similarity-checking"}],"deposited":{"date-parts":[[2025,10,9]],"date-time":"2025-10-09T17:13:20Z","timestamp":1760030000000},"score":1,"resource":{"primary":{"URL":"https:\/\/dl.acm.org\/doi\/10.1145\/3720422"}},"subtitle":[],"short-title":[],"issued":{"date-parts":[[2025,4,9]]},"references-count":61,"journal-issue":{"issue":"OOPSLA1","published-print":{"date-parts":[[2025,4,9]]}},"alternative-id":["10.1145\/3720422"],"URL":"https:\/\/doi.org\/10.1145\/3720422","relation":{},"ISSN":["2475-1421"],"issn-type":[{"type":"electronic","value":"2475-1421"}],"subject":[],"published":{"date-parts":[[2025,4,9]]},"assertion":[{"value":"2024-10-08","order":0,"name":"received","label":"Received","group":{"name":"publication_history","label":"Publication History"}},{"value":"2025-02-18","order":2,"name":"accepted","label":"Accepted","group":{"name":"publication_history","label":"Publication History"}},{"value":"2025-04-09","order":3,"name":"published","label":"Published","group":{"name":"publication_history","label":"Publication History"}}]}}